0

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

Akshay J
  • 93
  • 1
  • 9

1 Answers1

0

This happens if your PATH variable includes that module's directory on your machine but not on Jenkins.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Josh Clark
  • 964
  • 1
  • 9
  • 17
  • Hi Josh, my Jenkins and user machine are the same. Also, checked the PATH values locally and through Jenkins shell, both does not contain the project modules entry. – Akshay J Apr 02 '20 at 15:11
  • Hey @AkshayJ, I recently was working through this issue with virtual environments as well. I learned that you can add a .pth file to the site-packages directory of your python installation to add a direction to your Python path. Check out [this answer](https://stackoverflow.com/a/10739838/3801865). This might not actually be your issue, just throwing it out there. – Josh Clark Apr 02 '20 at 15:17
  • Issue is resolved: After creating virtual environment, I just changed the directory to the root (cd ${WORKSPACE}/{project root DIR}) of the project and it started picking up the test scripts. Thanks for your help. :) – Akshay J Apr 03 '20 at 05:36