Time will tell.
我们一般在设计测试用例时,要求不要有先后顺序,用例可以打乱执行,这样才能达到测试效果。如果用例写了先后顺序,后面可能会出现一些问题,比如上个用例返回数据作为下个用例传参。
而 github 上有个pytest-ordering
插件可以控制用例的执行顺序。
1、安装
pip install pytest-ordering
2、案例
pytest 默认的执行顺序,是按test_ording.py
文件写的用例先后顺序执行。
代码:
# test_ording.py
import pytest
def test_foo():
print("用例11111111111")
assert Truedef test_bar():
print("用例22222222222")
assert Truedef test_g():
print("用例333333333333333")
assert True
结果:
D:\demo>pytest test_ording.py -vs
============