一、setup/teardown
通过添加setup与teardown方法,使得在执行每个用例时前后都有出现。
案例代码:
class TestAA:
def setup(self):
print('开始--------')
@pytest.mark.smoke
def testaa(self):
time_loc=time.strftime('%H-%M-%S',time.localtime())
time.sleep(2)
print(time_loc+'您好bb啊')
@pytest.mark.run(order=1) #表示在执行顺序中,第1个去执行
def testbb(self):
time_loc=time.strftime('%H-%M-%S',time.localtime())
print(time_loc+'您好aa啊')
def teardown(self):
print('结束-----------------\n')
运行结果:
二、setup_class/teardown_class
在所有的用例之前只执行一次
使用场景:
在每个类执行前后的初始化工作,如:创建/销毁日志对象,创建/销毁数据库的连接,创建/销毁接口的请求对象。
案例代码:
class TestAA:
def setup_class