[英]pytest command line argument failing
I have added conftest.py at the same directory level as my test file . 我在与测试文件相同的目录级别添加了conftest.py。 The content of my conftest.py : 我的conftest.py的内容:
import pytest
def pytest_addoption(parser):
parser.addoption("--l", action="store", help="Get license value")
@pytest.fixture
def lic(request):
return request.config.getoption("--l")
and following is my test file def 以下是我的测试文件def
def test(lic):
print "testing license : %s"%lic
assert 0
But i still get following error: 但是我仍然收到以下错误:
pytest .\source\test_latestLinuxAgent.py --l=test
pytest : usage: pytest [options] [file_or_dir] [file_or_dir] [...]
At line:1 char:1
+ pytest .\source\test_latestLinuxAgent.py --l=test
pytest: error: ambiguous option: --l=test could match --lf, --last-failed
As the response says, --l
option is ambiguous. 如响应所示, --l
选项是不明确的。 What does it mean? 这是什么意思?
Let me explain it with an example. 让我用一个例子来解释它。 If you have --zaaaa
option, the shortcut for it is --z
. 如果您具有--zaaaa
选项,则其快捷方式是--z
。 However, there is one condition: --zaaaa
must be the only option starting with z
char. 但是,有一个条件:-- --zaaaa
必须是以z
char开头的唯一选项。 Otherwise, the interpreter does not know which option should be chosen. 否则,解释器不知道应该选择哪个选项。
You can't define --l
option because there are two options starting with l
char: --lf
and --last-failed
. 您无法定义--l
选项,因为有两个以l
char开头的选项:-- --lf
和--last-failed
。
I suggest creating non-conflicting option, --license
would be nice. 我建议创建非冲突选项,-- --license
会很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.