diff --git a/changelog/571.deprecation.rst b/changelog/571.deprecation.rst new file mode 100644 index 000000000..73750838d --- /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 db43c6ca3..7e241ae1b 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -49,3 +49,8 @@ NO_PRINT_LOGS = PytestDeprecationWarning( "--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 62e2155a2..1e16d092d 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -4,6 +4,7 @@ from typing import Optional 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 cafc87f2e..861938617 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -221,6 +221,7 @@ class TestGeneralUsage: "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 20afa42d0..90c248b4a 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -257,6 +257,7 @@ class TestCollectPluginHookRelay: assert len(wascalled) == 1 assert wascalled[0].ext == ".abc" + @pytest.mark.filterwarnings("ignore:.*pytest_collect_directory.*") def test_pytest_collect_directory(self, testdir): wascalled = []