使用pytest测试框架写的用例,测试函数生成的self变量在别的测试函数里用不了

请教一下,如标题所述,使用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'

img

每个用例应该是独立运行的,如果要用self,,试试在__init__()里面定义