import pytest
def pytest_configure(config):
config.addinivalue_line("markers", "slow: mark test as slow to run")
config.addinivalue_line("markers", "victor: mark test as slow to run") # 与pytest.ini 中一样就是注册一下但是仍可以使用未定义的标记
def pytest_addoption(parser): # 添加命令行参数
parser.addoption(
"--your_name", action="store", default="tom", help="my option: type1 or type2"
)
parser.addoption(
"--runslow", action="store_true", default=False, help="run slow tests"
)
def pytest_collection_modifyitems(config, items):
name = config.getoption("your_name")
if config.getoption("--runslow"): # 获取命令行参数runslow 如果有直接返回不跳过
# --runslow given in cli: do not skip slow tests
print("runslow given in cli: do not skip slow tests")
return
skip_slow = pytest.mark
pytest_addoption 动态添加命令行参数并获取,与 自定义跳过某些标记的测试(pytest_collection_modifyitems)
最新推荐文章于 2024-04-28 20:56:44 发布