I'm trying to use Jenkins for running python tests and creating coverage reports.
I have compiled application that is bound with python - lets call it pythonX - that setts up environment for executing parts of that application. Now, when I want to run tests for some part of the code I can just run
d:\my_app\sys\pythonX.exe -m pytest d:\user\repos\my_app\tests\unit
and all works really nice because pythonX
knows where everything is.
For that I'm using
stage('Run tests') {
steps {
bat 'd:\\my_app\\sys\\pythonX.exe -m pytest d:\\user\\repos\\my_app\\tests\\unit'
}
}
.
But there is a problem, this pythonX
is running the tests on the code that is shipped with the application, so already built and all that. What I wan't is to run tests on the code that is still local.
The pythonX
adds a environment variable PYTHONPATH
for specifying where the source code is but whenever I start the pythonX.exe
via bat
it changes whatever I've added before.
What I've tried first is using the withEnv
like so
stage('Run tests') {
steps {
withEnv(['PATH+PYTHONPATH=d:\\user\\repos\\my_app']){
bat 'd:\\my_app\\sys\\pythonX.exe -m pytest d:\\user\\repos\\my_app\\tests\\unit'
}
}
}
but it doesn't help.
What I've tried is else is setting up the environment, then changing the PYTHONPATH
variable, and then running the tests via pythonX
in existing environment.
This is the code
stage('Run tests') {
steps {
bat '''
d:\\my_app\\sys\\pythonX.exe --debug=cmd
set PYTHONPATH= d:\\user\\repos\\my_app;%PYTHONPATH%
d:\\my_app\\sys\\pythonX.exe -m pytest d:\\user\\repos\\my_app\\tests\\unit
'''
}
}
but this doesn't work. I presume that is overwrites the PYTHONPATH
environment variable with it's own.
Does anyone know how to overcome this?