【问题标题】:How to fix "pytest: error: unrecognized arguments: -n"如何修复“pytest:错误:无法识别的参数:-n”
【发布时间】:2022-08-23 00:47:50
【问题描述】:

嗨,我正在尝试在 azure 管道上并行运行我的测试(pytest-xdist)。 到目前为止,测试运行得非常好。 突然,pytest 抛出一个奇怪的错误,说“无法识别的参数”。

文件名:integration_test.py 使用的命令:pytest -n 5 --tb=short integration_test.py -v -s --> 并行运行 5 个测试 测试总数:57 版本: pytest==6.2.5 pytest-xdist==2.3.0 甚至尝试使用这两个模块的最新版本。

错误 : 错误:用法:pytest [options] [file_or_dir] [file_or_dir] [...] pytest:错误:无法识别的参数:-n integration_test.py

我该如何克服这个错误?

  • 您还没有安装 pytest-xdist,它添加了 -n 参数。
  • 我已经安装了 pytest-xdist 模块。
  • 仍然面临问题
  • 那么你可能没有为正确的解释器安装它。运行pytest -v --collect-only,插件中是否列出了xdist?最好将输出添加到问题中。

标签: pytest pytest-xdist


【解决方案1】:

这个错误是你遇到的:

正如 hoefling 提到的,解决方案是安装 pytest-xdist:

pip install pytest-xdist

【讨论】:

    【解决方案2】:

    在 MacOS 上,运行 pytest 的 Python 版本可能与您想象的不同。

    $ pytest
    ============================================================================== test session starts ===============================================================================
    platform darwin -- Python 3.9.12, pytest-6.2.5, py-1.10.0, pluggy-0.13.1
    rootdir: [REDACTED]
    plugins: anyio-3.5.0, cov-3.0.0
    

    尽管

    $ python3 -m pytest
    ============================================================================== test session starts ===============================================================================
    platform darwin -- Python 3.10.6, pytest-7.1.2, pluggy-1.0.0
    rootdir: [REDACTED]
    plugins: xdist-2.5.0, forked-1.4.0, pylama-8.4.1
    

    小心,并将其作为模块启动:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-02
      • 2020-12-18
      • 2019-11-06
      相关资源
      最近更新 更多