当有几十个用例(.py)时,且每个py文件的业务都是相关的,后一个业务的需要等前一个业务执行完,如:商品上架addproduct.py,下单付款等(buy.py),评论(pinglun.py)。此时我要保证其中部分用例的执行先后顺序时需要怎么办
使用 pytest-ordering 解决:
@pytest.mark.run(order=0) # 需要安装 pytest-ordering 库才会生效
def test_count(self, show):
assert count_num([1, 2, 3]) != 4
@pytest.mark.run(order=1)
def test_count2(self):
assert count_num([1, 2, 3, 4]) != 4