一、不同文件的执行顺序

 按照目录文件名顺序执行,目录结构如下:

pytest---用例执行顺序

用例执行顺序:

pytest---用例执行顺序

二、同一文件下的执行顺序

按照用例顺序从上到下执行,示例代码:

import pytest


class TestF():
    def testz(self):
        print('testz')

    def test3(self):
        print('test3')

def test2():
    print('test2')

def test1():
    print('test1')

def testb():
    print('testb')

def testa():
    print('testa')

if __name__ == '__main__':
    pytest.main()

执行结果:

pytest---用例执行顺序

三、改变用例执行顺序

pip install pytest-ordering

示例代码:

import pytest


class TestF():
    def testz(self):
        print('testz')

    def test3(self):
        print('test3')

def test2():
    print('test2')

def test1():
    print('test1')

@pytest.mark.run(order=2)
def testb():
    print('testb')

@pytest.mark.run(order=1)
def testa():
    print('testa')

if __name__ == '__main__':
    pytest.main()

执行结果(对比二中的执行结果)

pytest---用例执行顺序

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-02-18
  • 2021-11-20
  • 2021-12-14
  • 2021-07-26
  • 2022-12-23
  • 2022-02-01
猜你喜欢
  • 2021-11-03
  • 2022-02-21
  • 2021-12-25
  • 2022-02-14
  • 2023-02-07
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案