diff --git a/doc/en/deprecations.rst b/doc/en/deprecations.rst index fb84647c5..12844265d 100644 --- a/doc/en/deprecations.rst +++ b/doc/en/deprecations.rst @@ -89,6 +89,15 @@ Removed Features As stated in our :ref:`backwards-compatibility` policy, deprecated features are removed only in major releases after an appropriate period of deprecation has passed. + +``pytest_collect_directory`` hook +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +.. versionremoved:: 6.0 + +The ``pytest_collect_directory`` has not worked properly for years (it was called +but the results were ignored). Users may consider using :func:`pytest_collection_modifyitems <_pytest.hookspec.pytest_collection_modifyitems>` instead. + TerminalReporter.writer ~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/doc/en/reference.rst b/doc/en/reference.rst index 3bc7161aa..eb2370ae4 100644 --- a/doc/en/reference.rst +++ b/doc/en/reference.rst @@ -656,7 +656,6 @@ Collection hooks .. autofunction:: pytest_collection .. autofunction:: pytest_ignore_collect -.. autofunction:: pytest_collect_directory .. autofunction:: pytest_collect_file .. autofunction:: pytest_pycollect_makemodule diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index 839348282..500fbe2f8 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -30,10 +30,6 @@ RESULT_LOG = PytestDeprecationWarning( "See https://docs.pytest.org/en/stable/deprecations.html#result-log-result-log for more information." ) -COLLECT_DIRECTORY_HOOK = PytestDeprecationWarning( - "The pytest_collect_directory hook is not working.\n" - "Please use collect_ignore in conftests or pytest_collection_modifyitems." -) PYTEST_COLLECT_MODULE = UnformattedWarning( PytestDeprecationWarning, diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index ce435901c..e60bfe9f9 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -12,7 +12,6 @@ from typing import Union import py.path from pluggy import HookspecMarker -from .deprecated import COLLECT_DIRECTORY_HOOK from _pytest.compat import TYPE_CHECKING if TYPE_CHECKING: @@ -262,16 +261,6 @@ def pytest_ignore_collect(path: py.path.local, config: "Config") -> Optional[boo """ -@hookspec(firstresult=True, warn_on_impl=COLLECT_DIRECTORY_HOOK) -def pytest_collect_directory(path: py.path.local, parent) -> Optional[object]: - """Called before traversing a directory for collection files. - - Stops at first non-None result, see :ref:`firstresult`. - - :param py.path.local path: The path to analyze. - """ - - def pytest_collect_file(path: py.path.local, parent) -> "Optional[Collector]": """Return collection Node or None for the given path. diff --git a/src/_pytest/nodes.py b/src/_pytest/nodes.py index 8e3e86a50..addeaf1c2 100644 --- a/src/_pytest/nodes.py +++ b/src/_pytest/nodes.py @@ -553,8 +553,6 @@ class FSCollector(Collector): for pat in self._norecursepatterns: if path.check(fnmatch=pat): return False - ihook = self.session.gethookproxy(path) - ihook.pytest_collect_directory(path=path, parent=self) return True def _collectfile( diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index d58b4fd03..039d8dad9 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -223,13 +223,12 @@ class TestGeneralUsage: "E {}: No module named 'qwerty'".format(exc_name), ] - @pytest.mark.filterwarnings("ignore::pytest.PytestDeprecationWarning") def test_early_skip(self, testdir): testdir.mkdir("xyz") testdir.makeconftest( """ import pytest - def pytest_collect_directory(): + def pytest_collect_file(): pytest.skip("early") """ ) diff --git a/testing/test_collection.py b/testing/test_collection.py index 01dbcc731..12030e56e 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -257,20 +257,6 @@ 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 = [] - - class Plugin: - def pytest_collect_directory(self, path): - wascalled.append(path.basename) - - testdir.mkdir("hello") - testdir.mkdir("world") - pytest.main(testdir.tmpdir, plugins=[Plugin()]) - assert "hello" in wascalled - assert "world" in wascalled - class TestPrunetraceback: def test_custom_repr_failure(self, testdir):