pytest -k 参数 从多个py文件中 指定要运行的方法

发布时间 2023-08-03 11:50:50作者: 胖豆芽
#D:\pythonProject0726\test_case\test_one.py
import time
def setup_module():
    print('准备测试数据')
def teardown_module():
    print('清理测试数据')
def test_oneone():
    ex=1
    real=1
    time.sleep(3)
    print('1==1')
    assert  ex==real
def test_oneonr():
    ex1=1
    real1=1
    time.sleep(3)
    print('1==1')
    assert  ex1==real1
# D:\pythonProject0726\test_case\test_two.py
import time
def test001():
    print('准备测试数据2')
def teardown_module():
    print('清理测试数据2')
def test_twoy():
    ex=1
    real=2
    time.sleep(3)
    print('1==2')
    assert ex==real
def test_twou():
    ex=1
    real=2
    time.sleep(3)
    print('1==2')
    assert ex==real
# D:\pythonProject0726\test_case\all_test_case.py
import pytest
import xdist

if __name__ == '__main__':
    pytest.main(['-vs'])

 

终端

 pytest -vs test_case -k "test001"