首页 > 其他 > 详细

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

时间:2019-09-22 14:54:27      阅读:163      评论:0      收藏:0      [点我收藏+]
场景:未考虑按自然顺序执行时,或想变更执行顺序,比如增加 数据的用例要先执行,再执行删除的用例。测试用例默认是按名 称顺序执行的。

 

• 解决:
• 安装: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

 

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

原文:https://www.cnblogs.com/QaStudy/p/11567039.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!