I am trying to set up workflow, which runs tests and comments test coverage. To achieve that, I need to save pytest call results into txt file. However, by doing so with following command:
Run pytest --cov=./ --junitxml=pytest.xml --capture=tee-sys --cov-report=term-missing:skip-covered tests/test_app.py | tee pytest-coverage.txt
I run into a problem, when if some tests fail whole workflow finishes anyway. What I want is workflow failing if any of the tests fail, otherwise I will use pytest-coverage.txt to print code coverage.
You might need to set pipefail
:
If set, the return value of a pipeline is the value of the last (rightmost) > command to exit with a non-zero status, or zero if all commands in the pipeline exit successfully. This option is disabled by default.
So the workflow step should be:
run: |
set -o pipefail
pytest --cov=./ \
--junitxml=pytest.xml \
--capture=tee-sys \
--cov-report=term-missing:skip-covered \
tests/test_app.py | \
tee pytest-coverage.txt
Notes:
shell
in job defaults.