diff --git a/src/_pytest/config/__init__.py b/src/_pytest/config/__init__.py index 90099137c41..4a961b934cb 100644 --- a/src/_pytest/config/__init__.py +++ b/src/_pytest/config/__init__.py @@ -262,19 +262,6 @@ def _prepareconfig( raise -def _fail_on_non_top_pytest_plugins(conftestpath, confcutdir): - msg = ( - "Defining 'pytest_plugins' in a non-top-level conftest is no longer supported:\n" - "It affects the entire test suite instead of just below the conftest as expected.\n" - " {}\n" - "Please move it to a top level conftest file at the rootdir:\n" - " {}\n" - "For more information, visit:\n" - " https://docs.pytest.org/en/latest/deprecations.html#pytest-plugins-in-non-top-level-conftest-files" - ) - fail(msg.format(conftestpath, confcutdir), pytrace=False) - - class PytestPluginManager(PluginManager): """ Overwrites :py:class:`pluggy.PluginManager ` to add pytest-specific @@ -499,12 +486,6 @@ def _importconftest(self, conftestpath): _ensure_removed_sysmodule(conftestpath.purebasename) try: mod = conftestpath.pyimport() - if ( - hasattr(mod, "pytest_plugins") - and self._configured - and not self._using_pyargs - ): - _fail_on_non_top_pytest_plugins(conftestpath, self._confcutdir) except Exception: raise ConftestImportFailure(conftestpath, sys.exc_info()) diff --git a/testing/test_config.py b/testing/test_config.py index 7d827a46896..82a2330fcbf 100644 --- a/testing/test_config.py +++ b/testing/test_config.py @@ -1,4 +1,3 @@ -import os import re import sys import textwrap @@ -1444,108 +1443,6 @@ def test_pytest_custom_cfg_unsupported(self, testdir): testdir.runpytest("-c", "custom.cfg") -class TestPytestPluginsVariable: - def test_pytest_plugins_in_non_top_level_conftest_unsupported(self, testdir): - testdir.makepyfile( - **{ - "subdirectory/conftest.py": """ - pytest_plugins=['capture'] - """ - } - ) - testdir.makepyfile( - """ - def test_func(): - pass - """ - ) - res = testdir.runpytest() - assert res.ret == 2 - msg = "Defining 'pytest_plugins' in a non-top-level conftest is no longer supported" - res.stdout.fnmatch_lines( - [ - "*{msg}*".format(msg=msg), - "*subdirectory{sep}conftest.py*".format(sep=os.sep), - ] - ) - - @pytest.mark.parametrize("use_pyargs", [True, False]) - def test_pytest_plugins_in_non_top_level_conftest_unsupported_pyargs( - self, testdir, use_pyargs - ): - """When using --pyargs, do not emit the warning about non-top-level conftest warnings (#4039, #4044)""" - - files = { - "src/pkg/__init__.py": "", - "src/pkg/conftest.py": "", - "src/pkg/test_root.py": "def test(): pass", - "src/pkg/sub/__init__.py": "", - "src/pkg/sub/conftest.py": "pytest_plugins=['capture']", - "src/pkg/sub/test_bar.py": "def test(): pass", - } - testdir.makepyfile(**files) - testdir.syspathinsert(testdir.tmpdir.join("src")) - - args = ("--pyargs", "pkg") if use_pyargs else () - res = testdir.runpytest(*args) - assert res.ret == (0 if use_pyargs else 2) - msg = ( - msg - ) = "Defining 'pytest_plugins' in a non-top-level conftest is no longer supported" - if use_pyargs: - assert msg not in res.stdout.str() - else: - res.stdout.fnmatch_lines(["*{msg}*".format(msg=msg)]) - - def test_pytest_plugins_in_non_top_level_conftest_unsupported_no_top_level_conftest( - self, testdir - ): - subdirectory = testdir.tmpdir.join("subdirectory") - subdirectory.mkdir() - testdir.makeconftest( - """ - pytest_plugins=['capture'] - """ - ) - testdir.tmpdir.join("conftest.py").move(subdirectory.join("conftest.py")) - - testdir.makepyfile( - """ - def test_func(): - pass - """ - ) - - res = testdir.runpytest_subprocess() - assert res.ret == 2 - msg = "Defining 'pytest_plugins' in a non-top-level conftest is no longer supported" - res.stdout.fnmatch_lines( - [ - "*{msg}*".format(msg=msg), - "*subdirectory{sep}conftest.py*".format(sep=os.sep), - ] - ) - - def test_pytest_plugins_in_non_top_level_conftest_unsupported_no_false_positives( - self, testdir - ): - testdir.makepyfile( - "def test_func(): pass", - **{ - "subdirectory/conftest": "pass", - "conftest": """ - import warnings - warnings.filterwarnings('always', category=DeprecationWarning) - pytest_plugins=['capture'] - """, - }, - ) - res = testdir.runpytest_subprocess() - assert res.ret == 0 - msg = "Defining 'pytest_plugins' in a non-top-level conftest is no longer supported" - assert msg not in res.stdout.str() - - def test_report_implicit_args(testdir, monkeypatch): p = testdir.makepyfile( """