pytest命令行参数失败

pytest command line argument failing

我已将 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")

下面是我的测试文件 def

   def  test(lic):
        print "testing license : %s"%lic
        assert 0

但我仍然得到以下错误:

   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

如响应所述,--l 选项不明确。这是什么意思?

我举个例子解释一下。如果你有 --zaaaa 选项,它的快捷方式是 --z。但是,有一个条件:--zaaaa 必须是唯一以 z 字符开头的选项。否则,解释器不知道应该选择哪个选项。

您不能定义 --l 选项,因为有两个选项以 l 字符开头:--lf--last-failed.

我建议创建 non-conflicting 选项,--license 会很好。