From cc0317405709fb08fe327e49a4998bb4d1df1520 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Thu, 20 Feb 2020 12:27:43 +0100 Subject: [PATCH 1/4] Fix pytest_ignore_collect hooks: do not return False It should only return `True` when something is to be ignored, not `False` otherwise typically. This caused e.g. bad interaction with the cacheprovider (before https://github.com/pytest-dev/pytest/pull/6448). --- src/_pytest/hookspec.py | 3 ++- src/_pytest/main.py | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index 62e2155a263..3021b1b79b2 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -198,7 +198,8 @@ def pytest_ignore_collect(path, config): This hook is consulted for all files and directories prior to calling more specific hooks. - Stops at first non-None result, see :ref:`firstresult` + Stops at first non-None result, see :ref:`firstresult`, i.e. you should + only return `False` if the file should never get ignored (by other hooks). :param path: a :py:class:`py.path.local` - the path to analyze :param _pytest.config.Config config: pytest config object diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 72e88b24418..8a9bd3d3d94 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -320,8 +320,6 @@ def pytest_ignore_collect(path, config): if not allow_in_venv and _in_venv(path): return True - return False - def pytest_collection_modifyitems(items, config): deselect_prefixes = tuple(config.getoption("deselect") or []) From 949ee2f05b8ff9b029afb4e6147e7031fd52a968 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 21 Feb 2020 12:57:07 +0100 Subject: [PATCH 2/4] keep None --- src/_pytest/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 8a9bd3d3d94..420ba75ca1c 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -319,6 +319,7 @@ def pytest_ignore_collect(path, config): allow_in_venv = config.getoption("collect_in_virtualenv") if not allow_in_venv and _in_venv(path): return True + return None def pytest_collection_modifyitems(items, config): From 1aa8747b6f5af4dfb45be146df44a8b546f40156 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 21 Feb 2020 12:58:33 +0100 Subject: [PATCH 3/4] typing --- src/_pytest/main.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/_pytest/main.py b/src/_pytest/main.py index 420ba75ca1c..73b1df7094e 100644 --- a/src/_pytest/main.py +++ b/src/_pytest/main.py @@ -33,6 +33,7 @@ if TYPE_CHECKING: from typing import Type + from typing_extensions import Literal from _pytest.python import Package @@ -295,7 +296,9 @@ def _in_venv(path): return any([fname.basename in activates for fname in bindir.listdir()]) -def pytest_ignore_collect(path, config): +def pytest_ignore_collect( + path: py.path.local, config: Config +) -> "Optional[Literal[True]]": ignore_paths = config._getconftest_pathlist("collect_ignore", path=path.dirpath()) ignore_paths = ignore_paths or [] excludeopt = config.getoption("ignore") From 00eb39d04fc304ab33eb7b979e181cc9f3174549 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 21 Feb 2020 13:00:27 +0100 Subject: [PATCH 4/4] revert doc --- src/_pytest/hookspec.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/_pytest/hookspec.py b/src/_pytest/hookspec.py index 3021b1b79b2..62e2155a263 100644 --- a/src/_pytest/hookspec.py +++ b/src/_pytest/hookspec.py @@ -198,8 +198,7 @@ def pytest_ignore_collect(path, config): This hook is consulted for all files and directories prior to calling more specific hooks. - Stops at first non-None result, see :ref:`firstresult`, i.e. you should - only return `False` if the file should never get ignored (by other hooks). + Stops at first non-None result, see :ref:`firstresult` :param path: a :py:class:`py.path.local` - the path to analyze :param _pytest.config.Config config: pytest config object