pytest用例执行顺序

发布时间 2023-08-09 13:33:00作者: 乐乐乐乐乐乐樂
py文件的执行顺序

pytest默认按字母顺序去执行的(小写英文-->大写英文--->0~9数字)

setup_module->setup_claas->setup_function->testcase->teardown_function->teardown_claas->teardown_module

文件按照ASCLL码排序

文件内默认按照从上到下进行执行

文件内的用例按照从上往下执行

例:
test_01
test_02
test_03
改变用例的执行顺序-装饰器@pytest.mark.run(order=x)

@pytest.mark.run(order=x) 需要 pip install pytest-ordering

@pytest.mark.run(order=x)

x是整数(可以是正数也可以是负数)
全为正数或负数时,值越晓,优先级越高
既有正数又有负数时,正数优先级高(-1,2,-3的执行顺序是2,-3,-1)
0是正整数中最小的,优先级最高的
@pytest.mark.run(order=0)
#俩个0时,就按照正常顺序执行

@pytest.mark.run(order=1)
@pytest.mark.run(order=2)
@pytest.mark.run(order=3)