pytest調用其他測試用例方法
一. 第一種方法,測試用例前置@pytest.fixture()
def test1():print("我是用例一")
@pytest.fixture(test1)
def test2():print("我是用例二")
二.第二種方法,如果不是同一文件中測試用例調用或者同一py文件中
def test1():print("我是用例一")
def test2():test1()print("我是用例二")
三.通過@pytest.mark.run()的方法
文件conftest.pydef pytest_sessionstart(session):def run_other_tests(item):# 在這里添加你想要運行的另一個測試文件的路徑item.config.runpytest(['test_case/soa/test_performance/test_bgm_check_cpu.py'])session.config.pluginmanager.register(run_other_tests, 'run')
文件test.py
@pytest.mark.run(target='test_case/soa/test_performance/test_bgm_check_cpu.py')def test_something_else():assert True
四:直接調用
test1.py
def test1():print("我是用例一")
teset2.py
def test1_run():
"""
-q:安靜模式,不輸出環境信息。
-v:豐富信息模式,輸出更詳細的用例執行信息。
-s:顯示程序中的print/logging輸出。
-x:出現一條測試用例失敗就退出測試
"""pytest.main(['test1.py'])def test2():print("我是用例二")