Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 0 additions & 19 deletions src/_pytest/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 <pluggy.PluginManager>` to add pytest-specific
Expand Down Expand Up @@ -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())

Expand Down
103 changes: 0 additions & 103 deletions testing/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import os
import re
import sys
import textwrap
Expand Down Expand Up @@ -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(
"""
Expand Down