如何防止自己吃掉我的一个测试参数?

时间:2018-03-09 17:59:37

标签: python pytest

我的测试模块中有:

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保持空白。我该如何防止帽子?

1 个答案:

答案 0 :(得分:0)

在调用AgentCOne之前,您似乎需要实例化c_bar因为c_bar不是静态方法(并且将第一个参数作为self)。

c = AgentCOne.c_bar(alpha, beta, delta)
# should be
c = AgentCOne().c_bar(alpha, beta, delta)