Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #571: deprecate pytest_collect_directory as ... #6847

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 missaligned since the removal of the Directory collector in 2010
nicoddemus marked this conversation as resolved.
Show resolved Hide resolved
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."
)
RonnyPfannschmidt marked this conversation as resolved.
Show resolved Hide resolved
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