[英]Python tests run locally on ubuntu but fails when run through Jenkins with error "ImportError while importing test module '/var/lib/jenkins/workspace"
Jenkins setup is on Ubuntu. Jenkins 设置在 Ubuntu 上。
Local: Created a virtual environment using python 3.6, running tests through command line using pythom -m pytest - ./{test.py} which is successful本地:使用 python 3.6 创建了一个虚拟环境,使用 pythom -m pytest - ./{test.py} 通过命令行运行测试成功
Jenkins job:詹金斯工作:
In the Build > Shell script, creating a virtual environment the same way done locally and running the commands.在 Build > Shell 脚本中,以与本地相同的方式创建虚拟环境并运行命令。
python3.6 -m venv jenkins-venv python3.6 -m venv jenkins-venv
source ${WORKSPACE}/jenkins-venv/bin/activate源 ${WORKSPACE}/jenkins-venv/bin/activate
pip install --no-cache-dir -r ${WORKSPACE}/project/requirements.txt pip install --no-cache-dir -r ${WORKSPACE}/project/requirements.txt
python -m pytest -v ${WORKSPACE}/project/test_day1.py python -m pytest -v ${WORKSPACE}/project/test_day1.py
Error: ERROR collecting scripts/ ImportError while importing test module '/var/lib/jenkins/workspace/job_name/project/test_Login.py'.错误:在导入测试模块“/var/lib/jenkins/workspace/job_name/project/test_Login.py”时收集脚本时出错/ImportError。
Hint: make sure your test modules/packages have valid Python names.提示:确保您的测试模块/包具有有效的 Python 名称。
ModuleNotFoundError: No module named ModuleNotFoundError: 没有命名模块
如果您的 PATH 变量在您的机器上包含该模块的目录,但在 Jenkins 上不包含该目录,则会发生这种情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.