请教一下,如标题所述,使用pytest,测试函数之间使用self实例变量会报错,这种机制是pytest故意为之还是不得已为之,为什么?
class Testdemo:
def test_step1(self):
name = 'jarry'
self.res = name.upper()
assert self.res=='JARRY'
def test_step2(self):
assert self.res=='jarry'
##
============================= test session starts =============================
collecting ... collected 2 items
test_1117.py::Testdemo::test_step1
test_1117.py::Testdemo::test_step2 PASSEDFAILED
zdebug\test_1117.py:14 (Testdemo.test_step2)
test_1117.py:16: in test_step2
assert self.res=='jarry'
E AttributeError: 'Testdemo' object has no attribute 'res'