默认跳过测试,除非 py.test 中存在命令行参数 [英] Default skip test unless command line parameter present in py.test
本文介绍了默认跳过测试,除非 py.test 中存在命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个持续 2 天的长时间运行测试,我不想将其包含在通常的测试运行中.我也不想输入命令行参数,这会在每次常规测试运行时取消选择它和其他测试.当我真正需要它时,我更愿意选择一个默认取消选择的测试.我尝试将测试从 test_longrun
重命名为 longrun
并使用命令
I have a long run test, which lasts 2 days, which I don't want to include in a usual test run. I also don't want to type command line parameters, that would deselect it and other tests at every usual test run. I would prefer to select a default-deselected test, when I actually need it. I tried renaming the test from test_longrun
to longrun
and use the command
py.test mytests.py::longrun
但这不起作用.
推荐答案
尝试将您的测试装饰为 @pytest.mark.longrun
try to decorate your test as @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')
这篇关于默认跳过测试,除非 py.test 中存在命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文