diff --git a/changelog/571.deprecation.rst b/changelog/571.deprecation.rst new file mode 100644 index 00000000000..73750838d5f --- /dev/null +++ b/changelog/571.deprecation.rst @@ -0,0 +1,3 @@ +Deprecate the unused/broken `pytest_collect_directory` hook. +It was misaligned since the removal of the ``Directory`` collector in 2010 +and incorrect/unusable as soon as collection was split from test execution. diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index db43c6ca3ef..7e241ae1b39 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -49,3 +49,8 @@ "--no-print-logs is deprecated and scheduled for removal in pytest 6.0.\n" "Please use --show-capture instead." ) + +COLLECT_DIRECTORY_HOOK = PytestDeprecationWarning( + "The pytest_collect_directory hook is not working.\n" + "Please use collect_ignore in conftests or pytest_collection_modifyitems." +) diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index 62e2155a263..1e16d092d0b 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -4,6 +4,7 @@ from pluggy import HookspecMarker +from .deprecated import COLLECT_DIRECTORY_HOOK from _pytest.compat import TYPE_CHECKING if TYPE_CHECKING: @@ -205,7 +206,7 @@ def pytest_ignore_collect(path, config): """ -@hookspec(firstresult=True) +@hookspec(firstresult=True, warn_on_impl=COLLECT_DIRECTORY_HOOK) def pytest_collect_directory(path, parent): """ called before traversing a directory for collection files. diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index cafc87f2e7d..861938617e8 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -221,6 +221,7 @@ def foo(): "E {}: No module named 'qwerty'".format(exc_name), ] + @pytest.mark.filterwarnings("always::pytest.PytestDeprecationWarning") def test_early_skip(self, testdir): testdir.mkdir("xyz") testdir.makeconftest( diff --git a/testing/test_collection.py b/testing/test_collection.py index 20afa42d0d4..90c248b4ab2 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -257,6 +257,7 @@ def pytest_collect_file(self, path): assert len(wascalled) == 1 assert wascalled[0].ext == ".abc" + @pytest.mark.filterwarnings("ignore:.*pytest_collect_directory.*") def test_pytest_collect_directory(self, testdir): wascalled = []