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("我是用例二")