Remove broken pytest_collect_directory hook

This commit is contained in:
Bruno Oliveira 2020-08-17 17:55:37 -03:00
parent 457d351941
commit 52b0cc4f19
7 changed files with 10 additions and 34 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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")
"""
)

View File

@ -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):