我的测试模块中有:
import pytest
from src.model_code.central import AgentBasic
class AgentBasicTestee(AgentBasic):
pass
@pytest.fixture()
def agentBasic():
return AgentBasicTestee()
@pytest.mark.parametrize('alpha, beta, delta, expected', [
(2, 1, 1, pytest.approx(0.5)),
(2, 2, 2, pytest.approx(-0.9375 / 0.75)),
])
def test_b3(agentBasic, AgentCOne,alpha, beta, delta, expected):
assert(agentBasic.b3(alpha, beta, delta) == expected)
并在我的导入模块中
from src.model_code.crra_utility import AgentCrra
AgentCOne = AgentCrra
class AgentBasic:
@staticmethod
def b3(alpha, beta, delta):
"""define matric element b3"""
k = AgentCOne.k_bar(alpha, beta, delta)
c = AgentCOne.c_bar(alpha, beta, delta)
return -c/k
我得到的错误信息是:
> c = AgentCOne.c_bar(alpha, beta, delta)
E TypeError: c_bar() missing 1 required positional argument: 'delta'
注意:
def c_bar(self, alpha, beta, delta):
"""non-stochastic steady-state for consumption"""
k = self.k_bar(alpha, beta, delta)
return k ** alpha - delta * k
到目前为止,self取了我的一个参数s.t. delta保持空白。我该如何防止帽子?
答案 0 :(得分:0)
在调用AgentCOne
之前,您似乎需要实例化c_bar
因为c_bar
不是静态方法(并且将第一个参数作为self
)。
c = AgentCOne.c_bar(alpha, beta, delta)
# should be
c = AgentCOne().c_bar(alpha, beta, delta)