13

I'm getting deprecation warning from my pipelines at circleci.

Message.

/home/circleci/evobench/env/lib/python3.7/site-packages/_pytest/junitxml.py:436: PytestDeprecationWarning: The 'junit_family' default value will change to 'xunit2' in pytest 6.0.

Command

- run:
    name: Tests
    command: |
      . env/bin/activate
      mkdir test-reports
      python -m pytest --junitxml=test-reports/junit.xml

How should I modify command to use xunit? Is it possible to a default tool, as it is mentioned in the message? I mean without specyfing xunit or junit.

Here's full pipeline.

Piotr Rarus
  • 884
  • 8
  • 16

4 Answers4

13

Run your command in this ways.

with xunit2

python -m pytest -o junit_family=xunit2 --junitxml=test-reports/junit.xml

with xunit1

python -m pytest -o junit_family=xunit1 --junitxml=test-reports/junit.xml or

python -m pytest -o junit_family=legacy --junitxml=test-reports/junit.xml

This here describes the change in detail:

The default value of junit_family option will change to xunit2 in pytest 6.0, given that this is the version supported by default in modern tools that manipulate this type of file.

In order to smooth the transition, pytest will issue a warning in case the --junitxml option is given in the command line but junit_family is not explicitly configured in pytest.ini:

PytestDeprecationWarning: The `junit_family` default value will change to 'xunit2' in pytest 6.0.   Add `junit_family=legacy` to your

pytest.ini file to silence this warning and make your suite compatible.

In order to silence this warning, users just need to configure the junit_family option explicitly:

[pytest]
junit_family=legacy
disco crazy
  • 31,313
  • 12
  • 80
  • 83
3

In your pytest.ini file add the following line:

junit_family=legacy

If you want to keep the default behavior of the --junitxml option. Or you can accept the new version, xunit2 but not explicitly defining the junit_family variable.

Essentially what the warning is saying is you are giving the --junitxml option in your

run           
  name: Tests

section not specifying the junit_family variable. You need to start to explicitly defining it to remove the warning or accept the new default.

This thread goes into more details about where to find the .ini file for pytest.

Edeki Okoh
  • 1,786
  • 15
  • 27
  • How can I dump artifacts without junit? I know all about quirks to use junit. I was wandering how can I use xunit, as I couldn't find it. – Piotr Rarus Feb 17 '20 at 10:35
1

For official statement/documentation about moving from xunit1 to xunit2 read: docs.pytest.org

Also if your project contains pytest.ini file you can set junit_family usage directly from the file like:

# pytest.ini
[pytest]
minversion = 6.0
junit_family=xunit2
junit_suite_name = Pytest Tests
addopts = -ra -q -v -s --junitxml=path/to/pytest_results/pytest.xml
dubaksk
  • 91
  • 2
  • 10
0

The other answers pretty much covered the means of specifying the junit family, either within pytest.ini or at the commandline with an ini option override.

It's worth looking at the differences between xunit1 and xunit2 for a concrete xml file. Doing a quick spot check on the differences I found these differences show in the image below for the following test module...

# test_stub.py

import sys
import pytest

def test_pass():
    assert True

def test_fail():
    assert False


if __name__ == "__main__":
    sys.exit(pytest.main([__file__] + sys.argv[1:]))

Pytest was ran under three separate configurations (which match the vertical order in the image)

# Default execution
pytest test_stub.py --junit-xml=out.xml 
pytest test_stub.py --junit-xml=out_xunit2.xml -o junit_family=xunit2

# Junit prefix execution
pytest test_stub.py --junit-prefix=FOOOP --junit-xml=out_prefix.xml
pytest test_stub.py --junit-prefix=FOOOP --junit-xml=out_prefix_xunit2.xml -o junit_family=xunit2

# Junit suite execution
pytest -o junit_suite_name=SUITE test_stub.py --junit-xml=out_suite.xml
pytest -o junit_suite_name=SUITE test_stub.py --junit-xml=out_suite_xunit2.xml -o junit_family=xunit2

All of the diffs pretty much highlight the fact that xunit2 omits the file and line attributes that showed up previously in xunit1. The other diffs were merely timestamp differences. Both junit_suite_name and junit-prefix behave as before.

junit xml differences

Another major difference is that for some reason record_property has been deprecated under the xunit2 schema.

PytestWarning: record_property is incompatible with junit_family 'xunit2' (use 'legacy' or 'xunit1')

https://docs.pytest.org/en/7.1.x/reference/reference.html#pytest.junitxml.record_property

jxramos
  • 7,356
  • 6
  • 57
  • 105