Skip to content

Commit

Permalink
Issue a warning to prepare change of 'junit_family' default value
Browse files Browse the repository at this point in the history
  • Loading branch information
nicoddemus authored and vinaycalastry committed Dec 11, 2019
1 parent bc5fc43 commit 07b07e7
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 4 deletions.
7 changes: 7 additions & 0 deletions changelog/6179.deprecation.rst
@@ -0,0 +1,7 @@
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``.

For more information, `see the docs <https://docs.pytest.org/en/latest/deprecations.html#junit-family-default-value-change-to-xunit2>`__.
23 changes: 23 additions & 0 deletions doc/en/deprecations.rst
Expand Up @@ -19,6 +19,7 @@ Below is a complete list of all pytest features which are considered deprecated.
:class:`_pytest.warning_types.PytestWarning` or subclasses, which can be filtered using
:ref:`standard warning filters <warnings>`.

<<<<<<< HEAD
``--no-print-logs`` command-line option
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -29,6 +30,28 @@ provide feedback.

``--show-capture`` command-line option was added in ``pytest 3.5.0` and allows to specify how to
display captured output when tests fail: ``no``, ``stdout``, ``stderr``, ``log`` or ``all`` (the default).
=======
``junit_family`` default value change to "xunit2"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

.. deprecated:: 5.2

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:

.. code-block:: ini
[pytest]
junit_family=legacy
>>>>>>> 2a67637ac... Issue a warning to prepare change of 'junit_family' default value


``funcargnames`` alias for ``fixturenames``
Expand Down
8 changes: 8 additions & 0 deletions src/_pytest/deprecated.py
Expand Up @@ -30,12 +30,20 @@
"See https://docs.pytest.org/en/latest/deprecations.html#result-log-result-log for more information."
)


FIXTURE_POSITIONAL_ARGUMENTS = PytestDeprecationWarning(
"Passing arguments to pytest.fixture() as positional arguments is deprecated - pass them "
"as a keyword argument instead."
)


NO_PRINT_LOGS = PytestDeprecationWarning(
"--no-print-logs is deprecated and scheduled for removal in pytest 6.0.\n"
"Please use --show-capture instead."
)


JUNIT_XML_DEFAULT_FAMILY = PytestDeprecationWarning(
"The 'junit_family' default value will change to 'xunit2' in pytest 6.0.\n"
"Add 'junit_family=legacy' to your pytest.ini file to silence this warning and make your suite compatible."
)
12 changes: 8 additions & 4 deletions src/_pytest/junitxml.py
Expand Up @@ -19,8 +19,10 @@
import py

import pytest
from _pytest import deprecated
from _pytest import nodes
from _pytest.config import filename_arg
from _pytest.warnings import _issue_warning_captured


class Junit(py.xml.Namespace):
Expand Down Expand Up @@ -421,23 +423,25 @@ def pytest_addoption(parser):
default="total",
) # choices=['total', 'call'])
parser.addini(
"junit_family",
"Emit XML for schema: one of legacy|xunit1|xunit2",
default="xunit1",
"junit_family", "Emit XML for schema: one of legacy|xunit1|xunit2", default=None
)


def pytest_configure(config):
xmlpath = config.option.xmlpath
# prevent opening xmllog on slave nodes (xdist)
if xmlpath and not hasattr(config, "slaveinput"):
junit_family = config.getini("junit_family")
if not junit_family:
_issue_warning_captured(deprecated.JUNIT_XML_DEFAULT_FAMILY, config.hook, 2)
junit_family = "xunit1"
config._xml = LogXML(
xmlpath,
config.option.junitprefix,
config.getini("junit_suite_name"),
config.getini("junit_logging"),
config.getini("junit_duration_report"),
config.getini("junit_family"),
junit_family,
config.getini("junit_log_passing_tests"),
)
config.pluginmanager.register(config._xml)
Expand Down
29 changes: 29 additions & 0 deletions testing/deprecated_test.py
Expand Up @@ -46,6 +46,7 @@ def test_external_plugins_integrated(testdir, plugin):
testdir.parseconfig("-p", plugin)


<<<<<<< HEAD
@pytest.mark.filterwarnings("default")
@pytest.mark.parametrize("config_mode", ["ini", "cmdline"])
def test_noprintlogs_is_deprecated_ini(testdir, config_mode):
Expand All @@ -61,10 +62,16 @@ def test_noprintlogs_is_deprecated_ini(testdir, config_mode):
assert config_mode == "cmdline"
args = ("--no-print-logs",)

=======
@pytest.mark.parametrize("junit_family", [None, "legacy", "xunit2"])
def test_warn_about_imminent_junit_family_default_change(testdir, junit_family):
"""Show a warning if junit_family is not defined and --junitxml is used (#6179)"""
>>>>>>> 2a67637ac... Issue a warning to prepare change of 'junit_family' default value
testdir.makepyfile(
"""
def test_foo():
pass
<<<<<<< HEAD
"""
)

Expand All @@ -75,3 +82,25 @@ def test_foo():
"*Please use --show-capture instead.*",
]
)
=======
"""
)
if junit_family:
testdir.makeini(
"""
[pytest]
junit_family={junit_family}
""".format(
junit_family=junit_family
)
)

result = testdir.runpytest("--junit-xml=foo.xml")
warning_msg = (
"*PytestDeprecationWarning: The 'junit_family' default value will change*"
)
if junit_family:
result.stdout.no_fnmatch_line(warning_msg)
else:
result.stdout.fnmatch_lines([warning_msg])
>>>>>>> 2a67637ac... Issue a warning to prepare change of 'junit_family' default value

0 comments on commit 07b07e7

Please sign in to comment.