简体   繁体   中英

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.

Local: Created a virtual environment using python 3.6, running tests through command line using pythom -m pytest - ./{test.py} which is successful

Jenkins job:

In the Build > Shell script, creating a virtual environment the same way done locally and running the commands.

python3.6 -m venv jenkins-venv

source ${WORKSPACE}/jenkins-venv/bin/activate

pip install --no-cache-dir -r ${WORKSPACE}/project/requirements.txt

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'.

Hint: make sure your test modules/packages have valid Python names.

ModuleNotFoundError: No module named

如果您的 PATH 变量在您的机器上包含该模块的目录,但在 Jenkins 上不包含该目录,则会发生这种情况。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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