Pytest AttributeError: ‘TestMyTest’ object has no attribute

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

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().

  1. @pytest.fixture(scope="module")
  2. def do_setup(run_apps):
  3. """
  4. Do setup
  5. """
  6. # Do something
  7. yield some_data
  8. class TestMyTest(BaseTestClass):
  9. ids = dict()
  10. task_id = list()
  11. output_json = None
  12. def test_init(self, do_setup):
  13. TestMyTest.var1 = Feature1()
  14. def test_1(self):
  15. 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:

确定