From 91384193794dcf8ae30778767546a2dad7bad845 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 19 Dec 2018 17:43:17 -0200 Subject: [PATCH 1/2] Remove support for '[pytest]' section in setup.cfg file Fix #3086 --- changelog/3086.removal.rst | 4 ++++ doc/en/deprecations.rst | 19 ++++++++++--------- src/_pytest/config/findpaths.py | 25 ++++++++----------------- src/_pytest/deprecated.py | 6 +----- testing/deprecated_test.py | 18 ++++++------------ 5 files changed, 29 insertions(+), 43 deletions(-) create mode 100644 changelog/3086.removal.rst diff --git a/changelog/3086.removal.rst b/changelog/3086.removal.rst new file mode 100644 index 00000000000..3974aa5004f --- /dev/null +++ b/changelog/3086.removal.rst @@ -0,0 +1,4 @@ +``[pytest]`` section in **setup.cfg** files is not longer supported, use ``[tool:pytest]`` instead. ``setup.cfg`` files +are meant for use with ``distutils``, and a section named ``pytest`` has notoriously been a source of conflicts and bugs. + +Note that for **pytest.ini** and **tox.ini** files the section remains ``[pytest]``. diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index b37be1b7f63..781d05b774d 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -125,15 +125,6 @@ To update the code, use ``pytest.param``: - -[pytest] section in setup.cfg files -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -.. deprecated:: 3.0 - -``[pytest]`` sections in ``setup.cfg`` files should now be named ``[tool:pytest]`` -to avoid conflicts with other distutils commands. - Result log (``--result-log``) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -185,6 +176,16 @@ Switch over to the ``@pytest.fixture`` decorator: return SomeData() + +[pytest] section in setup.cfg files +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +*Removed in version 4.0.* + +``[pytest]`` sections in ``setup.cfg`` files should now be named ``[tool:pytest]`` +to avoid conflicts with other distutils commands. + + Metafunc.addcall ~~~~~~~~~~~~~~~~ diff --git a/src/_pytest/config/findpaths.py b/src/_pytest/config/findpaths.py index eecc92606d4..a0f16134d1e 100644 --- a/src/_pytest/config/findpaths.py +++ b/src/_pytest/config/findpaths.py @@ -3,6 +3,7 @@ import py from .exceptions import UsageError +from _pytest.outcomes import fail def exists(path, ignore=EnvironmentError): @@ -34,15 +35,10 @@ def getcfg(args, config=None): iniconfig = py.iniconfig.IniConfig(p) if "pytest" in iniconfig.sections: if inibasename == "setup.cfg" and config is not None: - from _pytest.warnings import _issue_warning_captured - from _pytest.warning_types import RemovedInPytest4Warning - - _issue_warning_captured( - RemovedInPytest4Warning( - CFG_PYTEST_SECTION.format(filename=inibasename) - ), - hook=config.hook, - stacklevel=2, + + fail( + CFG_PYTEST_SECTION.format(filename=inibasename), + pytrace=False, ) return base, p, iniconfig["pytest"] if ( @@ -112,14 +108,9 @@ def determine_setup(inifile, args, rootdir_cmd_arg=None, config=None): inicfg = iniconfig[section] if is_cfg_file and section == "pytest" and config is not None: from _pytest.deprecated import CFG_PYTEST_SECTION - from _pytest.warnings import _issue_warning_captured - - # TODO: [pytest] section in *.cfg files is deprecated. Need refactoring once - # the deprecation expires. - _issue_warning_captured( - CFG_PYTEST_SECTION.format(filename=str(inifile)), - config.hook, - stacklevel=2, + + fail( + CFG_PYTEST_SECTION.format(filename=str(inifile)), pytrace=False ) break except KeyError: diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index af1b5c792fd..467c735847f 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -14,7 +14,6 @@ from _pytest.warning_types import PytestDeprecationWarning from _pytest.warning_types import RemovedInPytest4Warning -from _pytest.warning_types import UnformattedWarning YIELD_TESTS = "yield tests were removed in pytest 4.0 - {name} will be ignored" @@ -31,10 +30,7 @@ "'request' is a reserved name for fixtures and will raise an error in future versions" ) -CFG_PYTEST_SECTION = UnformattedWarning( - RemovedInPytest4Warning, - "[pytest] section in {filename} files is deprecated, use [tool:pytest] instead.", -) +CFG_PYTEST_SECTION = "[pytest] section in {filename} files is no longer supported, change to [tool:pytest] instead." GETFUNCARGVALUE = RemovedInPytest4Warning( "getfuncargvalue is deprecated, use getfixturevalue" diff --git a/testing/deprecated_test.py b/testing/deprecated_test.py index d392ac7d9f1..bb2c17c45e9 100644 --- a/testing/deprecated_test.py +++ b/testing/deprecated_test.py @@ -10,8 +10,7 @@ pytestmark = pytest.mark.pytester_example_path("deprecated") -@pytest.mark.filterwarnings("default") -def test_pytest_setup_cfg_deprecated(testdir): +def test_pytest_setup_cfg_unsupported(testdir): testdir.makefile( ".cfg", setup=""" @@ -19,14 +18,11 @@ def test_pytest_setup_cfg_deprecated(testdir): addopts = --verbose """, ) - result = testdir.runpytest() - result.stdout.fnmatch_lines( - ["*pytest*section in setup.cfg files is deprecated*use*tool:pytest*instead*"] - ) + with pytest.raises(pytest.fail.Exception): + testdir.runpytest() -@pytest.mark.filterwarnings("default") -def test_pytest_custom_cfg_deprecated(testdir): +def test_pytest_custom_cfg_unsupported(testdir): testdir.makefile( ".cfg", custom=""" @@ -34,10 +30,8 @@ def test_pytest_custom_cfg_deprecated(testdir): addopts = --verbose """, ) - result = testdir.runpytest("-c", "custom.cfg") - result.stdout.fnmatch_lines( - ["*pytest*section in custom.cfg files is deprecated*use*tool:pytest*instead*"] - ) + with pytest.raises(pytest.fail.Exception): + testdir.runpytest("-c", "custom.cfg") def test_getfuncargvalue_is_deprecated(request): From a93f41233a8f4edadb33a055396247ef1ede210a Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 19 Dec 2018 18:09:47 -0200 Subject: [PATCH 2/2] Raise an error if pytest_plugins is defined in a non-top-level conftest.py file Fix #4548 --- changelog/4548.removal.rst | 3 +++ doc/en/deprecations.rst | 20 ++++++++++---------- src/_pytest/config/__init__.py | 11 ++++++----- src/_pytest/deprecated.py | 10 +++++++--- testing/deprecated_test.py | 22 ++++++++-------------- 5 files changed, 34 insertions(+), 32 deletions(-) create mode 100644 changelog/4548.removal.rst diff --git a/changelog/4548.removal.rst b/changelog/4548.removal.rst new file mode 100644 index 00000000000..bd47b1d5172 --- /dev/null +++ b/changelog/4548.removal.rst @@ -0,0 +1,3 @@ +An error is now raised if the ``pytest_plugins`` variable is defined in a non-top-level ``conftest.py`` file (i.e., not residing in the ``rootdir``). + +See our `docs `__ for more information. diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index 781d05b774d..ca95bab389b 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -81,16 +81,6 @@ As part of a large :ref:`marker-revamp`, :meth:`_pytest.nodes.Node.get_marker` i :ref:`the documentation ` on tips on how to update your code. -pytest_plugins in non-top-level conftest files -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -.. deprecated:: 3.5 - -Defining ``pytest_plugins`` is now deprecated in non-top-level conftest.py -files because they will activate referenced plugins *globally*, which is surprising because for all other pytest -features ``conftest.py`` files are only *active* for tests at or below it. - - marks in ``pytest.mark.parametrize`` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -242,6 +232,16 @@ You can consult `funcarg comparison section in the docs