Skip to content

Commit 68777aa

Browse files
committed
Issue a warning to prepare change of 'junit_family' default value
Fix pytest-dev#6179
1 parent f91bf48 commit 68777aa

File tree

5 files changed

+67
-4
lines changed

5 files changed

+67
-4
lines changed

changelog/6179.deprecation.rst

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
The default value of ``junit_family`` option will change to ``xunit2`` in pytest 6.0, given
2+
that this is the version supported by default in modern tools that manipulate this type of file.
3+
4+
In order to smooth the transition, pytest will issue a warning in case the ``--junitxml`` option
5+
is given in the command line but ``junit_family`` is not explicitly configured in ``pytest.ini``.
6+
7+
For more information, `see the docs <https://docs.pytest.org/en/latest/deprecations.html#junit-family-default-value-change-to-xunit2>`__.

doc/en/deprecations.rst

+18
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,24 @@ Below is a complete list of all pytest features which are considered deprecated.
1919
:class:`_pytest.warning_types.PytestWarning` or subclasses, which can be filtered using
2020
:ref:`standard warning filters <warnings>`.
2121

22+
``junit_family`` default value change to "xunit2"
23+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24+
25+
.. deprecated:: 5.2
26+
27+
The default value of ``junit_family`` option will change to ``xunit2`` in pytest 6.0, given
28+
that this is the version supported by default in modern tools that manipulate this type of file.
29+
30+
In order to smooth the transition, pytest will issue a warning in case the ``--junitxml`` option
31+
is given in the command line but ``junit_family`` is not explicitly configured in ``pytest.ini``.
32+
33+
In order to silence this warning, users just need to configure the ``junit_family`` option:
34+
35+
.. code-block:: ini
36+
37+
[pytest]
38+
junit_family=legacy
39+
2240
2341
``funcargnames`` alias for ``fixturenames``
2442
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

src/_pytest/deprecated.py

+5
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,8 @@
3434
"Passing arguments to pytest.fixture() as positional arguments is deprecated - pass them "
3535
"as a keyword argument instead."
3636
)
37+
38+
JUNIT_XML_DEFAULT_FAMILY = PytestDeprecationWarning(
39+
"The 'junit_family' default value will change to 'xunit2' in pytest 6.0.\n"
40+
"Add 'junit_family=legacy' to your pytest.ini file to silence this warning and make your suite compatible."
41+
)

src/_pytest/junitxml.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@
1919
import py
2020

2121
import pytest
22+
from _pytest import deprecated
2223
from _pytest import nodes
2324
from _pytest.config import filename_arg
25+
from _pytest.warnings import _issue_warning_captured
2426

2527

2628
class Junit(py.xml.Namespace):
@@ -421,23 +423,25 @@ def pytest_addoption(parser):
421423
default="total",
422424
) # choices=['total', 'call'])
423425
parser.addini(
424-
"junit_family",
425-
"Emit XML for schema: one of legacy|xunit1|xunit2",
426-
default="xunit1",
426+
"junit_family", "Emit XML for schema: one of legacy|xunit1|xunit2", default=None
427427
)
428428

429429

430430
def pytest_configure(config):
431431
xmlpath = config.option.xmlpath
432432
# prevent opening xmllog on slave nodes (xdist)
433433
if xmlpath and not hasattr(config, "slaveinput"):
434+
junit_family = config.getini("junit_family")
435+
if not junit_family:
436+
_issue_warning_captured(deprecated.JUNIT_XML_DEFAULT_FAMILY, config.hook, 2)
437+
junit_family = "xunit1"
434438
config._xml = LogXML(
435439
xmlpath,
436440
config.option.junitprefix,
437441
config.getini("junit_suite_name"),
438442
config.getini("junit_logging"),
439443
config.getini("junit_duration_report"),
440-
config.getini("junit_family"),
444+
junit_family,
441445
config.getini("junit_log_passing_tests"),
442446
)
443447
config.pluginmanager.register(config._xml)

testing/deprecated_test.py

+29
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,32 @@ def test_external_plugins_integrated(testdir, plugin):
4444

4545
with pytest.warns(pytest.PytestConfigWarning):
4646
testdir.parseconfig("-p", plugin)
47+
48+
49+
@pytest.mark.parametrize("junit_family", [None, "legacy", "xunit2"])
50+
def test_warn_about_imminent_junit_family_default_change(testdir, junit_family):
51+
"""Show a warning if junit_family is not defined and --junitxml is used (#6179)"""
52+
testdir.makepyfile(
53+
"""
54+
def test_foo():
55+
pass
56+
"""
57+
)
58+
if junit_family:
59+
testdir.makeini(
60+
"""
61+
[pytest]
62+
junit_family={junit_family}
63+
""".format(
64+
junit_family=junit_family
65+
)
66+
)
67+
68+
result = testdir.runpytest("--junit-xml=foo.xml")
69+
warning_msg = (
70+
"*PytestDeprecationWarning: The 'junit_family' default value will change*"
71+
)
72+
if junit_family:
73+
result.stdout.no_fnmatch_line(warning_msg)
74+
else:
75+
result.stdout.fnmatch_lines([warning_msg])

0 commit comments

Comments
 (0)