setup/teardown函数
函数级别:
import pytest
class Test002:
def setup(self):
print("---------start")
pass
def test_001(self):
print("----------test001")
def test_002(self):
print("----------test002")
def teardown(self):
print("----------stop")
pass
if __name__ == '__main__':
pytest.main(['-s', 'test002.py'])
结果:
---------start
----------test001
.----------stop
---------start
----------test002
.----------stop
每执行一个函数就会执行一次setup和teardown
类级别:
import pytest
class Test002:
def setup_class(self):
print("---------start")
pass
def test_001(self):
print("----------test001")
def test_002(self):
print("----------test002")
def teardow