Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
505 views
in Technique[技术] by (71.8m points)

python - How can I prevent self from eating one of my test parameters?

I have in my test module:

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)

and in my import module

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

The error message I get is:

> c = AgentCOne.c_bar(alpha, beta, delta) E TypeError: c_bar() missing 1 required positional argument: 'delta' Note:

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 

So far, self takes one of my parameters s.t. delta stays empty. How can I prevent hat?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It seems like you need to instantiate AgentCOne before calling c_bar on it because c_bar is not a static method (and will take the first argument as self).

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...