2024-09-27 17:54:49 发布
网友
我有一个长时间运行测试,持续2天,我不想把它包括在通常的测试运行中。我也不想输入命令行参数,这样会在每次正常的测试运行中取消选择它和其他测试。我宁愿选择一个默认的取消选择的测试,当我真正需要它的时候。我尝试将测试从test_longrun重命名为longrun,并使用命令
test_longrun
longrun
py.test mytests.py::longrun
但这行不通。在
作为上述pytest_configure解决方案的替代方案,我找到了pytest.mark.skipif。在
pytest_configure
pytest.mark.skipif
您需要将pytest_addoption()放入conftest.py
pytest_addoption()
conftest.py
def pytest_addoption(parser): parser.addoption(' longrun', action='store_true', dest="longrun", default=False, help="enable longrundecorated tests")
在测试文件中使用skipif。在
skipif
在命令行中
py.test
不会执行test_longrun(),但是
test_longrun()
py.test longrun
也将执行test_longrun()。在
尝试将测试装饰为@pytest.mark.longrun
@pytest.mark.longrun
在你的conftest.py
def pytest_addoption(parser): parser.addoption(' longrun', action='store_true', dest="longrun", default=False, help="enable longrundecorated tests") def pytest_configure(config): if not config.option.longrun: setattr(config.option, 'markexpr', 'not longrun')
作为上述
pytest_configure
解决方案的替代方案,我找到了pytest.mark.skipif
。在您需要将
pytest_addoption()
放入conftest.py
在测试文件中使用
^{pr2}$skipif
。在在命令行中
不会执行
test_longrun()
,但是也将执行
test_longrun()
。在尝试将测试装饰为
@pytest.mark.longrun
在你的
conftest.py
相关问题 更多 >
编程相关推荐