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

Deprecate pytest_collect_directory

Fix #571

Co-authored-by: Daniel Hahler <github@thequod.de>
This commit is contained in:
Ronny Pfannschmidt 2020-03-03 22:58:14 +01:00 committed by GitHub
parent b11bfa106c
commit 9fd71d6fe0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 1 deletions

View File

@ -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.

View File

@ -49,3 +49,8 @@ NO_PRINT_LOGS = PytestDeprecationWarning(
"--no-print-logs is deprecated and scheduled for removal in pytest 6.0.\n" "--no-print-logs is deprecated and scheduled for removal in pytest 6.0.\n"
"Please use --show-capture instead." "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."
)

View File

@ -4,6 +4,7 @@ from typing import Optional
from pluggy import HookspecMarker from pluggy import HookspecMarker
from .deprecated import COLLECT_DIRECTORY_HOOK
from _pytest.compat import TYPE_CHECKING from _pytest.compat import TYPE_CHECKING
if 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): def pytest_collect_directory(path, parent):
""" called before traversing a directory for collection files. """ called before traversing a directory for collection files.

View File

@ -221,6 +221,7 @@ class TestGeneralUsage:
"E {}: No module named 'qwerty'".format(exc_name), "E {}: No module named 'qwerty'".format(exc_name),
] ]
@pytest.mark.filterwarnings("always::pytest.PytestDeprecationWarning")
def test_early_skip(self, testdir): def test_early_skip(self, testdir):
testdir.mkdir("xyz") testdir.mkdir("xyz")
testdir.makeconftest( testdir.makeconftest(

View File

@ -257,6 +257,7 @@ class TestCollectPluginHookRelay:
assert len(wascalled) == 1 assert len(wascalled) == 1
assert wascalled[0].ext == ".abc" assert wascalled[0].ext == ".abc"
@pytest.mark.filterwarnings("ignore:.*pytest_collect_directory.*")
def test_pytest_collect_directory(self, testdir): def test_pytest_collect_directory(self, testdir):
wascalled = [] wascalled = []