Issue a warning to prepare change of 'junit_family' default val… (#6186)
Issue a warning to prepare change of 'junit_family' default value
This commit is contained in:
		
						commit
						99f487864c
					
				| 
						 | 
					@ -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>`__.
 | 
				
			||||||
| 
						 | 
					@ -19,6 +19,27 @@ 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
 | 
					:class:`_pytest.warning_types.PytestWarning` or subclasses, which can be filtered using
 | 
				
			||||||
:ref:`standard warning filters <warnings>`.
 | 
					:ref:`standard warning filters <warnings>`.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					``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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
``funcargnames`` alias for ``fixturenames``
 | 
					``funcargnames`` alias for ``fixturenames``
 | 
				
			||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 | 
					~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -34,3 +34,8 @@ FIXTURE_POSITIONAL_ARGUMENTS = PytestDeprecationWarning(
 | 
				
			||||||
    "Passing arguments to pytest.fixture() as positional arguments is deprecated - pass them "
 | 
					    "Passing arguments to pytest.fixture() as positional arguments is deprecated - pass them "
 | 
				
			||||||
    "as a keyword argument instead."
 | 
					    "as a keyword argument 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."
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -19,8 +19,10 @@ from datetime import datetime
 | 
				
			||||||
import py
 | 
					import py
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import pytest
 | 
					import pytest
 | 
				
			||||||
 | 
					from _pytest import deprecated
 | 
				
			||||||
from _pytest import nodes
 | 
					from _pytest import nodes
 | 
				
			||||||
from _pytest.config import filename_arg
 | 
					from _pytest.config import filename_arg
 | 
				
			||||||
 | 
					from _pytest.warnings import _issue_warning_captured
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Junit(py.xml.Namespace):
 | 
					class Junit(py.xml.Namespace):
 | 
				
			||||||
| 
						 | 
					@ -421,9 +423,7 @@ def pytest_addoption(parser):
 | 
				
			||||||
        default="total",
 | 
					        default="total",
 | 
				
			||||||
    )  # choices=['total', 'call'])
 | 
					    )  # choices=['total', 'call'])
 | 
				
			||||||
    parser.addini(
 | 
					    parser.addini(
 | 
				
			||||||
        "junit_family",
 | 
					        "junit_family", "Emit XML for schema: one of legacy|xunit1|xunit2", default=None
 | 
				
			||||||
        "Emit XML for schema: one of legacy|xunit1|xunit2",
 | 
					 | 
				
			||||||
        default="xunit1",
 | 
					 | 
				
			||||||
    )
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -431,13 +431,17 @@ def pytest_configure(config):
 | 
				
			||||||
    xmlpath = config.option.xmlpath
 | 
					    xmlpath = config.option.xmlpath
 | 
				
			||||||
    # prevent opening xmllog on slave nodes (xdist)
 | 
					    # prevent opening xmllog on slave nodes (xdist)
 | 
				
			||||||
    if xmlpath and not hasattr(config, "slaveinput"):
 | 
					    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(
 | 
					        config._xml = LogXML(
 | 
				
			||||||
            xmlpath,
 | 
					            xmlpath,
 | 
				
			||||||
            config.option.junitprefix,
 | 
					            config.option.junitprefix,
 | 
				
			||||||
            config.getini("junit_suite_name"),
 | 
					            config.getini("junit_suite_name"),
 | 
				
			||||||
            config.getini("junit_logging"),
 | 
					            config.getini("junit_logging"),
 | 
				
			||||||
            config.getini("junit_duration_report"),
 | 
					            config.getini("junit_duration_report"),
 | 
				
			||||||
            config.getini("junit_family"),
 | 
					            junit_family,
 | 
				
			||||||
            config.getini("junit_log_passing_tests"),
 | 
					            config.getini("junit_log_passing_tests"),
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        config.pluginmanager.register(config._xml)
 | 
					        config.pluginmanager.register(config._xml)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -44,3 +44,32 @@ def test_external_plugins_integrated(testdir, plugin):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    with pytest.warns(pytest.PytestConfigWarning):
 | 
					    with pytest.warns(pytest.PytestConfigWarning):
 | 
				
			||||||
        testdir.parseconfig("-p", plugin)
 | 
					        testdir.parseconfig("-p", plugin)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					@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)"""
 | 
				
			||||||
 | 
					    testdir.makepyfile(
 | 
				
			||||||
 | 
					        """
 | 
				
			||||||
 | 
					        def test_foo():
 | 
				
			||||||
 | 
					            pass
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    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])
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue