python - 在 Azure DevOps Pipeline 中找不到 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 ://docs.microsoft.com/en-us/azure/devops/pipelines/ecosystems/python?view=azure-devops
运行 Pipeline 会导致上述步骤出错:
pytest: command not found
如果您希望查看完整的回溯:
我尝试过的其他事情:
在官方 pytest 站点(https://docs.pytest.org/en/stable/getting-started.html)之后,我尝试在安装命令中添加一个标志:
pip install -U pytest
,但结果相同。
是什么阻止了 Pipeline 发现已安装的 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 安装的模块不会被识别为系统级命令。
推荐阅读
- node.js - Nodemailer 不适用于 Lambda 函数
- python - PYOMO:使用 IPOPT 给出浮点值的二进制变量
- python - 从 Excel 表为 PCA 准备数据集
- c# - C# 9.0 从类创建记录
- c - 如何在 C 中打印字符串或整数?
- django - ModuleNotFoundError:没有命名的模块
在尝试让 Django 上 Heroku 时? - java - Java没有任何导入别名机制,我有两个同名的导入语句
- git - Git克隆未加载
- android - 当应用程序进入后台时使Android WebView暂停并在返回前台时恢复
- c++ - 如何通过填充或截断另一个输入字符串来构造字符串?