pytest [email protected] ()

@ pytest.mark.usefixtures ()
Tenga en cuenta la interpretación en el código (1), (2)

# coding=utf-8
import pytest

@pytest.fixture()
def test_case_3():
    print('---3号用例完成---')

@pytest.fixture()
def test_case_4():
    print('---4号用例完成---')

@pytest.fixture()
def test_case_5():
    print('---5号用例完成---')

@pytest.fixture()
def test_case_6():
    print('---6号用例完成---')

@pytest.fixture()
def test_case_7():
    print('---7号用例完成---')

# (1)这里按照【从下到上的顺序】,执行优先级是3、4、5
@pytest.mark.usefixtures('test_case_5')
@pytest.mark.usefixtures('test_case_4')
@pytest.mark.usefixtures('test_case_3')
class Testlogin001:

    def test_case_1(self):
        print('---1号用例完成---')

    # (2)这里按照调用了前面的函数test_case_6,局部的调用,执行优先级是最高的。
    @pytest.mark.usefixtures('test_case_7')
    @pytest.mark.usefixtures('test_case_6')
    def test_case_2(self):
        print('---2号用例完成---')


if __name__ == "__main__":
    pytest.main(['-vs', 'test_1.py'])

C:\Python39\python.exe D:/se_frame/Cases/MapAaaCases/test_1.py
collecting ... collected 2 items

test_1.py::Testlogin001::test_case_1 
启动浏览器
---进入要执行模块的的界面---
---3号用例完成---
---4号用例完成---
---5号用例完成---
---1号用例完成---
PASSED
退出浏览器

test_1.py::Testlogin001::test_case_2 
启动浏览器
---进入要执行模块的的界面---
---6号用例完成---
---7号用例完成---
---3号用例完成---
---4号用例完成---
---5号用例完成---
---2号用例完成---
PASSED
退出浏览器

Supongo que te gusta

Origin blog.csdn.net/weixin_45451320/article/details/113673413
Recomendado
Clasificación