如何使用简短表单向Pytest添加自定义标志
我正在关注这如何将自定义参数添加到Pytest中,以便使用自定义标记进行跳过测试。它有效,但我似乎无法自定义使用标志的简短版本。
我已经将这些功能添加到我的conftest.py
:
def pytest_addoption(parser):
parser.addoption("-fs", dest='full_suite', action="store_true",
help="Run the full test suite. Includes tests marked with the mark.full_suite flag")
def pytest_runtest_setup(item):
if 'full_suite' in item.keywords and not item.config.getoption("-fs"):
pytest.skip("You need the -fs option to run this test")
然后写下此测试:
@pytest.mark.full_suite
def test_something():
assert True
如果我使用长选项,例如-fs
,而不是<代码> -fs ,它将起作用,DEST将分配给fs
。对于简短的选项,显然我需要提供dest
关键字。但是我这样做了,我添加了dest ='full_suite
。尽管如此,我还是得到了这个错误:
....
self.option_id = str(option)
File "/home/jokea/Carbonspace/cs-landsat-sentinel/.python3.8_env/lib/python3.8/site-packages/_pytest/config/argparsing.py", line 326, in __repr__
args += ["dest: " + repr(self.dest)]
AttributeError: 'Argument' object has no attribute 'dest'
我缺少什么?
I was following this answer about how to add custom arguments to pytest in order to skip tests with the custom marker. It works, but I can't seem to customize it to use a short version of the flag.
I've added these functions to my conftest.py
:
def pytest_addoption(parser):
parser.addoption("-fs", dest='full_suite', action="store_true",
help="Run the full test suite. Includes tests marked with the mark.full_suite flag")
def pytest_runtest_setup(item):
if 'full_suite' in item.keywords and not item.config.getoption("-fs"):
pytest.skip("You need the -fs option to run this test")
And then I write this test:
@pytest.mark.full_suite
def test_something():
assert True
If I use the long option, for example, --fs
, rather than -fs
, it will work, and dest will be assigned to fs
. With the short option, I'm apparently required to supply the dest
keyword. But I did this, I added dest='full_suite
. Despite that, I get this error:
....
self.option_id = str(option)
File "/home/jokea/Carbonspace/cs-landsat-sentinel/.python3.8_env/lib/python3.8/site-packages/_pytest/config/argparsing.py", line 326, in __repr__
args += ["dest: " + repr(self.dest)]
AttributeError: 'Argument' object has no attribute 'dest'
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论