How to not mark Jenkins job as FAILURE when pytest tests fail How to not mark Jenkins job as FAILURE when pytest tests fail jenkins jenkins

How to not mark Jenkins job as FAILURE when pytest tests fail


Your attempt does not work because Jenkins runs the shell with the errexit (-e) option enabled and that causes the shell to exit right after the pytest command before it reaches your if statement. There is a one-liner however that will work because it is executed as one statement: https://stackoverflow.com/a/31114992/1070890

So your build step would look like this:

sh 'cd tests && python -m pytest || [[ $? -eq 1 ]]'


My solution was to implement the support myself in pytest-custom-exit-code and create a pull request.

From version 0.3.0 of the plugin I can use pytest --suppress-tests-failed-exit-code to get the desired behavior.