简体   繁体   English

詹金斯:第 5 行:pytest:找不到命令

[英]Jenkins: line 5: pytest: command not found

I am trying to run a unit test in Jenkins (Jenkins isn't being run locally) for a python script using pytest.我正在尝试在 Jenkins 中运行单元测试(Jenkins 不在本地运行),用于使用 pytest 的 python 脚本。

My Jenkins congif file pulls source code from bitbucket, and in the build section I selected Execute shell with the following commands.我的 Jenkins congif 文件从 bitbucket 中提取源代码,在构建部分我选择了使用以下命令Execute shell

pip3 install --upgrade pip
pip3 install numpy
pip3 install pytest
pytest test.py

The error I get is我得到的错误是

/home/jenkins/tmp/jenkins6809923023096290887.sh: line 5: pytest: command not found

I notice that pytest is installed, but in a different folder as reported in a preceding line:我注意到 pytest 已安装,但位于前一行中报告的不同文件夹中:

Requirement already satisfied: pytest in /home/jenkins/.local/lib/python3.6/site-packages (6.0.1)

Can anyone help with how to get Jenkins to run pytest from the necessary directory?任何人都可以帮助如何让 Jenkins 从必要的目录运行 pytest? More generally, does anyone know of up to date tutorials on using pytest with Jenkins?更一般地说,有没有人知道在 Jenkins 中使用 pytest 的最新教程?

Better off explicitly calling your version of Python as shown below.最好显式调用您的 Python 版本,如下所示。

python3.6 -m pip --upgrade pip
python3.6 -m pip install numpy pytest
python3.6 -m pytest test.py

Thanks to @gold_cy for their answer.感谢@gold_cy 的回答。 It didn't work for me, but the following did work它对我不起作用,但以下确实有效

pip3 --install --upgrade pip
pip3 install numpy pytest
python -m pytest test.py

I believe the reason this works is in accordance with the docs ...我相信这样做的原因是根据文档...

[Calling via python] is almost equivalent to invoking the command line script pytest [...] directly, except that calling via python will also add the current directory to sys.path. 【通过python调用】几乎相当于直接调用命令行脚本pytest[...],只不过通过python调用还会把当前目录添加到sys.path中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM