pytest#

The pytest framework supports JUnit reports out-of-the-box via the --junitxml flag:

pytest --junitxml=junit.xml

Better results#

To decrease report variance we recommend omitting test setup and teardown from individual test durations by adding the following to pytest.ini:

[pytest]
junit_duration_report = call

Further details in official pytest docs.