英文:
Pytest AttributeError: 'TestMyTest' object has no attribute
问题
当运行测试时,为什么会出现一些测试失败并出现异常 AttributeError: 'TestMyTest' object has no attribute 'var1'?
var1 在 test_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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论