python自动化测试——pytest测试用例setup和teardown
import pytest
class TestCase():
def setup_class(self):
print("setup_class:所有用例执行之前")
def setup_method(self):
print("setup_method: 每个用例开始前执行")
def teardown_method(self):
print("teardown_method: 每个用例结束后执行")
def teardown_class(self):
print("teardown_class:所有用例执行之后")
def test_A(self):
print("用例A")
assert True
def test_B(self):
print("用例B")
assert True
执行命令:pytest -s testOrder.py
执行顺序
setUpClass->setUp->testA->tearDown->setUp->testB>tearDown->tearDownClass