1、pytest 中的 setup 和 teardown
- 固定函数名称如下(函数名称不能写错)
def setup(self): print("setup_function--->") def teardown(self): print("teardown_function--->")
- 实例如下
import pytest class Test(): def setup(self): print("setup_function--->") def teardown(self): print("teardown_function--->") def test_01(self): print("深圳多测师") def test_02(self): print("广州多测师") def test_03(self): print("上海多测师") if __name__ == '__main__': pytest.main(["-s","test_demo1.py"]) # 结果如下 test_demo1.py setup_function---> 深圳多测师 .teardown_function---> setup_function---> 广州多测师 .teardown_function---> setup_function---> 上海多测师 .teardown_function--->