Skip to content

Commit 9fd71d6

Browse files
fix #571: deprecate pytest_collect_directory as ... (#6847)
Deprecate pytest_collect_directory Fix #571 Co-authored-by: Daniel Hahler <[email protected]>
1 parent b11bfa1 commit 9fd71d6

File tree

5 files changed

+12
-1
lines changed

5 files changed

+12
-1
lines changed

Diff for: changelog/571.deprecation.rst

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Deprecate the unused/broken `pytest_collect_directory` hook.
2+
It was misaligned since the removal of the ``Directory`` collector in 2010
3+
and incorrect/unusable as soon as collection was split from test execution.

Diff for: src/_pytest/deprecated.py

+5
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,8 @@
4949
"--no-print-logs is deprecated and scheduled for removal in pytest 6.0.\n"
5050
"Please use --show-capture instead."
5151
)
52+
53+
COLLECT_DIRECTORY_HOOK = PytestDeprecationWarning(
54+
"The pytest_collect_directory hook is not working.\n"
55+
"Please use collect_ignore in conftests or pytest_collection_modifyitems."
56+
)

Diff for: src/_pytest/hookspec.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from pluggy import HookspecMarker
66

7+
from .deprecated import COLLECT_DIRECTORY_HOOK
78
from _pytest.compat import TYPE_CHECKING
89

910
if TYPE_CHECKING:
@@ -205,7 +206,7 @@ def pytest_ignore_collect(path, config):
205206
"""
206207

207208

208-
@hookspec(firstresult=True)
209+
@hookspec(firstresult=True, warn_on_impl=COLLECT_DIRECTORY_HOOK)
209210
def pytest_collect_directory(path, parent):
210211
""" called before traversing a directory for collection files.
211212

Diff for: testing/acceptance_test.py

+1
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def foo():
221221
"E {}: No module named 'qwerty'".format(exc_name),
222222
]
223223

224+
@pytest.mark.filterwarnings("always::pytest.PytestDeprecationWarning")
224225
def test_early_skip(self, testdir):
225226
testdir.mkdir("xyz")
226227
testdir.makeconftest(

Diff for: testing/test_collection.py

+1
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ def pytest_collect_file(self, path):
257257
assert len(wascalled) == 1
258258
assert wascalled[0].ext == ".abc"
259259

260+
@pytest.mark.filterwarnings("ignore:.*pytest_collect_directory.*")
260261
def test_pytest_collect_directory(self, testdir):
261262
wascalled = []
262263

0 commit comments

Comments
 (0)