【问题标题】:pytest command line argument failingpytest 命令行参数失败
【发布时间】:2017-05-25 12:07:24
【问题描述】:

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

【问题讨论】:

    标签: python command-line-arguments pytest


    【解决方案1】:

    正如回复所说,--l 选项不明确。什么意思?

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

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

    我建议创建非冲突选项,--license 会很好。

    【讨论】:

    • 谢谢这是问题!
    猜你喜欢
    • 1970-01-01
    • 2022-10-21
    • 2020-09-09
    • 2020-11-27
    • 1970-01-01
    • 2021-08-14
    • 2020-08-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多