Pytest中如何解决测试用例的依赖执行问题

http://www.51testing.com/html/34/n-4474534.html?nomobile=1

https://www.cnblogs.com/se7enjean/p/13513131.html

 

不止针对单个用例,可以测试类之间互相依赖

需要指定执行顺序

 

test_01依赖test_02

 

# test_01.py

import pytest


@pytest.mark.run(order=2)
@pytest.mark.dependency(depends=["从项目根目录开始的相对路径/test_32.py::Test_02::test_02"], scope='session')
class Test_01:
    def test_01(self):
        assert True



 

# test_02.py


import pytest


@pytest.mark.run(order=1)
@pytest.mark.dependency()
class Test_02:

    def test_02(self):
        assert True

 

posted @ 2021-07-06 22:11  mkay  阅读(123)  评论(0)    收藏  举报