From 933f3025562da71e6bda5b2caab81172c43600de Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sun, 1 Mar 2020 14:01:31 +0100 Subject: [PATCH 1/4] fix #571: deprecate pytest_collect_directory as its missaligned since 2010 --- changelog/571.deprecation.rst | 1 + src/_pytest/deprecated.py | 5 +++++ src/_pytest/hookspec.py | 3 ++- 3 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 changelog/571.deprecation.rst diff --git a/changelog/571.deprecation.rst b/changelog/571.deprecation.rst new file mode 100644 index 00000000000..1454e07eb9b --- /dev/null +++ b/changelog/571.deprecation.rst @@ -0,0 +1 @@ +Deprecate he unused/broken `pytest_collect_directory` hook. diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index db43c6ca3ef..df8ae16a831 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -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 was intended to be deprecated since 2014\n" + "as it's missaligned since the removal of Directory as collector in 2010" +) diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index 62e2155a263..1e16d092d0b 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -4,6 +4,7 @@ from pluggy import HookspecMarker +from .deprecated import COLLECT_DIRECTORY_HOOK from _pytest.compat import 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): """ called before traversing a directory for collection files. From e3f258555c7d468cb9b99ae30a46d3d42558cc97 Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sun, 1 Mar 2020 15:48:55 +0100 Subject: [PATCH 2/4] filter deprecation warning for collect_directory test --- testing/acceptance_test.py | 1 + testing/test_collection.py | 1 + 2 files changed, 2 insertions(+) diff --git a/testing/acceptance_test.py b/testing/acceptance_test.py index cafc87f2e7d..861938617e8 100644 --- a/testing/acceptance_test.py +++ b/testing/acceptance_test.py @@ -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( diff --git a/testing/test_collection.py b/testing/test_collection.py index 20afa42d0d4..90c248b4ab2 100644 --- a/testing/test_collection.py +++ b/testing/test_collection.py @@ -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 = [] From 62b28acef4dbfae9c550093adce6945ecd6cc55b Mon Sep 17 00:00:00 2001 From: Ronny Pfannschmidt Date: Sun, 1 Mar 2020 20:27:15 +0100 Subject: [PATCH 3/4] fixup: correct changelog/deprecations warnings --- changelog/571.deprecation.rst | 4 +++- src/_pytest/deprecated.py | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/changelog/571.deprecation.rst b/changelog/571.deprecation.rst index 1454e07eb9b..c739bcdbb0d 100644 --- a/changelog/571.deprecation.rst +++ b/changelog/571.deprecation.rst @@ -1 +1,3 @@ -Deprecate he unused/broken `pytest_collect_directory` hook. +Deprecate the unused/broken `pytest_collect_directory` hook. +It was missaligned since the removal of the Directory collector in 2010 +and incorrect/unusable as soon as collection was split from test execution. diff --git a/src/_pytest/deprecated.py b/src/_pytest/deprecated.py index df8ae16a831..7e241ae1b39 100644 --- a/src/_pytest/deprecated.py +++ b/src/_pytest/deprecated.py @@ -51,6 +51,6 @@ ) COLLECT_DIRECTORY_HOOK = PytestDeprecationWarning( - "the pytest_collect_directory was intended to be deprecated since 2014\n" - "as it's missaligned since the removal of Directory as collector in 2010" + "The pytest_collect_directory hook is not working.\n" + "Please use collect_ignore in conftests or pytest_collection_modifyitems." ) From d99d001909f22dfdb51f6688448902956b76ca65 Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Tue, 3 Mar 2020 18:34:20 -0300 Subject: [PATCH 4/4] Update changelog/571.deprecation.rst Co-Authored-By: Daniel Hahler --- changelog/571.deprecation.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog/571.deprecation.rst b/changelog/571.deprecation.rst index c739bcdbb0d..73750838d5f 100644 --- a/changelog/571.deprecation.rst +++ b/changelog/571.deprecation.rst @@ -1,3 +1,3 @@ Deprecate the unused/broken `pytest_collect_directory` hook. -It was missaligned since the removal of the Directory collector in 2010 +It was misaligned since the removal of the ``Directory`` collector in 2010 and incorrect/unusable as soon as collection was split from test execution.