Skip to content

Commit

Permalink
fix #571: deprecate pytest_collect_directory as ... (#6847)
Browse files Browse the repository at this point in the history
Deprecate pytest_collect_directory

Fix #571

Co-authored-by: Daniel Hahler <[email protected]>
  • Loading branch information
RonnyPfannschmidt and blueyed authored Mar 3, 2020
1 parent b11bfa1 commit 9fd71d6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions changelog/571.deprecation.rst
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 5 additions & 0 deletions src/_pytest/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)
3 changes: 2 additions & 1 deletion src/_pytest/hookspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from pluggy import HookspecMarker

from .deprecated import COLLECT_DIRECTORY_HOOK
from _pytest.compat import TYPE_CHECKING

if TYPE_CHECKING:
Expand Down Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions testing/acceptance_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions testing/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []

Expand Down

0 comments on commit 9fd71d6

Please sign in to comment.