微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

pytest-调整测试用例的执行顺序

场景:未考虑按自然顺序执行时,或想变更执行顺序,比如增加 数据的用例要先执行,再执行删除的用例。测试用例认是按名 称顺序执行的。

 

解决:
• 安装:pip install pytest-ordering

• 在测试方法上加下面装饰器

•@pytest.mark.last    ---最后一个执行
• @pytest.mark.run(order=1)---第几个执行

 

pytest认按字母顺序去执行的

 

import pytest
@pytest.mark.run(order=1)
def test_01():
print('test01')

@pytest.mark.run(order=2)
def test_02():
print('test01')
@pytest.mark.last
def test_06():
print('test01')

def test_04():
print('test01')

def test_05():
print('test01')
@pytest.mark.run(order=3)
def test_03():
print('test01')

pytest_order.py::test_01 PASSED [ 16%]test01

pytest_order.py::test_02 PASSED [ 33%]test01

pytest_order.py::test_03 PASSED [ 50%]test01

pytest_order.py::test_04 PASSED [ 66%]test01

pytest_order.py::test_05 PASSED [ 83%]test01

pytest_order.py::test_06 PASSED [100%]test01

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐