pythonpath in declarative pipepline built on docker slave

16 views
Skip to first unread message

Omeka

unread,
Dec 20, 2016, 3:19:48 PM12/20/16
to Jenkins Users
hello,

i am looking for a way to set PYTHONPATH to the workspace / current directory of a build that executes unit test with pytest  and avoid the following
error messages:

[Tests] ______________ ERROR collecting tests/unit/drive/test_config.py _______________
[Tests] tests/unit/drive/test_config.py:3: in <module>
[Tests]     from drive import config
[Tests] E   ImportError: No module named 'drive'
[Tests] ______________ ERROR collecting tests/unit/drive/test_helpers.py ______________
[Tests] tests/unit/drive/test_helpers.py:3: in <module>
[Tests]     from drive import helpers
[Tests] E   ImportError: No module named 'drive'
[Tests] ______________ ERROR collecting tests/unit/drive/test_service.py ______________
[Tests] tests/unit/drive/test_service.py:5: in <module>
[Tests]     from drive import service
[Tests] E   ImportError: No module named 'drive'
[Tests] ___________ ERROR collecting tests/unit/drive/test_transformers.py ____________
[Tests] tests/unit/drive/test_transformers.py:5: in <module>
[Tests]     from drive import transformers
[Tests] E   ImportError: No module named 'drive'
[Tests] =========================== 4 error in 0.25 seconds ============================

the build is excuted in docker container based on the official python 3.5 image

I have to admit i have been playing with python for about just two weeks so i might be missing something.

Best regards
Omeka

Eric Pyle

unread,
Dec 20, 2016, 3:26:38 PM12/20/16
to jenkins...@googlegroups.com
This is really a Python issue, not Jenkins. But here's how I do it. PYTHONPATH environment variable is automatically appended to sys.path in Python. So in your Python script, just directly add the relevant directory (can be a relative or absolute path):

import sys
sys.path.append('path/to/my_dir')

Eric
--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jenkinsci-use...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/c3a15a5c-011c-4986-b1d3-cfc669a87804%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages