python - 在 Azure DevOps 管道中找不到 Pytest

标签 python bash azure-devops azure-pipelines pytest

在我的 Azure DevOps 管道中

( https://dev.azure.com/TheNewThinkTank/dark-matter-attractor/_build?definitionId=2&_a=summary )

我有一个测试阶段,我希望在相应的 Azure DevOps 存储库中的所有 Python 文件上安装和运行 pytest

(https://dev.azure.com/TheNewThinkTank/_git/dark-matter-attractor)。

Pytest的安装和运行方式遵循微软官方文档:

- script: |
    pip install pytest
    pip install pytest-cov
    pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml --cov-report=html
  displayName: 'Test with pytest'

可以在以下位置找到:https://learn.microsoft.com/en-us/azure/devops/pipelines/ecosystems/python?view=azure-devops

运行流水线导致上述步骤出错: pytest:找不到命令

如果你想看到完整的回溯:

https://dev.azure.com/TheNewThinkTank/dark-matter-attractor/_build/results?buildId=62&view=logs&j=792982d5-3bb1-5d82-222e-228148b73448&t=1f7e9bd0-3cdf-5b91-30b0-87c9b2af71b7

我尝试过的其他事情:

在官方 pytest 站点 ( https://docs.pytest.org/en/stable/getting-started.html ) 之后,我尝试在安装命令中添加一个标志: pip install -U pytest,但结果相同。

是什么阻止管道发现已安装的 pytest 模块?

最佳答案

请尝试python -m pytest:

- script: |
    pip install pytest
    pip install pytest-cov
    python -m pytest tests --doctest-modules --junitxml=junit/test-results.xml --cov=. --cov-report=xml --cov-report=html
  displayName: 'Test with pytest'

通过 pip 安装的模块不会被识别为系统级命令。

关于python - 在 Azure DevOps 管道中找不到 Pytest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64527843/

相关文章:

c# - 如何查找我的 Azure 构建代理的 C# 版本

python - Pandas :逐行比较数据框中的所有值

python - 在 Python 中对日期时间进行计算

linux - 从文件中读取路径值, append 字符串覆盖shell linux中的变量

bash - ' ]' expected Bash syntax error - despite ` ]` 存在并被空间包围

ios - Azure Devops Apple App Store 版本。属性 'whatsNew' 缺少值

java - 使用 Python 正则表达式解析 Java Arrays.deepToString 输出的浮点字符串

python - 按日期 pandas 将行转为列

emacs - 来自 .bashrc 的命令在 Emacs 中不可用

azure-devops - 有没有办法在 Liquibase 数据库版本控制中包含带有更改日志的整个文件夹?