Pytest AttributeError: ‘TestMyTest’ object has no attribute

huangapple go评论64阅读模式
英文:

Pytest AttributeError: 'TestMyTest' object has no attribute

问题

当运行测试时,为什么会出现一些测试失败并出现异常 AttributeError: 'TestMyTest' object has no attribute 'var1'

var1test_init() 中被定义为类变量。然而,在 test_1() 中仍然会引发异常。

英文:

I have multiple tests written in the following format. When the test is run, why do some tests fail with exception AttributeError: 'TestMyTest' object has no attribute 'var1'?

var1 is defined as class variable in test_init(). Still the exception is thrown in test_1().

@pytest.fixture(scope="module")
def do_setup(run_apps):
    """
    Do setup
    """
    # Do something
    yield some_data


class TestMyTest(BaseTestClass):
    ids = dict()
    task_id = list()
    output_json = None

    def test_init(self, do_setup):
        TestMyTest.var1 = Feature1()

    def test_1(self):
        self._logger.info("self.var1: {}".format(self.var1))

答案1

得分: 0

var1没有被定义,因为test_init()失败了。

英文:

var1 was not defined as test_init() failed.

huangapple
  • 本文由 发表于 2023年4月4日 16:04:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/75926918.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定