Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
512 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 Answer

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...