aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/pytest/py3/_pytest/cacheprovider.py
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2025-05-05 12:31:52 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2025-05-05 12:41:33 +0300
commit6ff49ec58061f642c3a2f83c61eba12820787dfc (patch)
treec733ec9bdb15ed280080d31dea8725bfec717acd /contrib/python/pytest/py3/_pytest/cacheprovider.py
parenteefca8305c6a545cc6b16dca3eb0d91dcef2adcd (diff)
downloadydb-6ff49ec58061f642c3a2f83c61eba12820787dfc.tar.gz
Intermediate changes
commit_hash:8b3bb826b17db8329ed1221f545c0645f12c552d
Diffstat (limited to 'contrib/python/pytest/py3/_pytest/cacheprovider.py')
-rw-r--r--contrib/python/pytest/py3/_pytest/cacheprovider.py61
1 files changed, 28 insertions, 33 deletions
diff --git a/contrib/python/pytest/py3/_pytest/cacheprovider.py b/contrib/python/pytest/py3/_pytest/cacheprovider.py
index 1ecb8650580..49e38ed533f 100644
--- a/contrib/python/pytest/py3/_pytest/cacheprovider.py
+++ b/contrib/python/pytest/py3/_pytest/cacheprovider.py
@@ -1,4 +1,5 @@
"""Implementation of the cache provider."""
+
# This plugin was not named "cache" to avoid conflicts with the external
# pytest-cache version.
import dataclasses
@@ -6,6 +7,7 @@ import json
import os
from pathlib import Path
from typing import Dict
+from typing import final
from typing import Generator
from typing import Iterable
from typing import List
@@ -18,7 +20,6 @@ from .pathlib import rm_rf
from .reports import CollectReport
from _pytest import nodes
from _pytest._io import TerminalWriter
-from _pytest.compat import final
from _pytest.config import Config
from _pytest.config import ExitCode
from _pytest.config import hookimpl
@@ -27,10 +28,11 @@ from _pytest.deprecated import check_ispytest
from _pytest.fixtures import fixture
from _pytest.fixtures import FixtureRequest
from _pytest.main import Session
+from _pytest.nodes import Directory
from _pytest.nodes import File
-from _pytest.python import Package
from _pytest.reports import TestReport
+
README_CONTENT = """\
# pytest cache directory #
@@ -111,6 +113,7 @@ class Cache:
"""
check_ispytest(_ispytest)
import warnings
+
from _pytest.warning_types import PytestCacheWarning
warnings.warn(
@@ -217,42 +220,34 @@ class LFPluginCollWrapper:
self.lfplugin = lfplugin
self._collected_at_least_one_failure = False
- @hookimpl(hookwrapper=True)
- def pytest_make_collect_report(self, collector: nodes.Collector):
- if isinstance(collector, (Session, Package)):
- out = yield
- res: CollectReport = out.get_result()
-
+ @hookimpl(wrapper=True)
+ def pytest_make_collect_report(
+ self, collector: nodes.Collector
+ ) -> Generator[None, CollectReport, CollectReport]:
+ res = yield
+ if isinstance(collector, (Session, Directory)):
# Sort any lf-paths to the beginning.
lf_paths = self.lfplugin._last_failed_paths
# Use stable sort to priorize last failed.
def sort_key(node: Union[nodes.Item, nodes.Collector]) -> bool:
- # Package.path is the __init__.py file, we need the directory.
- if isinstance(node, Package):
- path = node.path.parent
- else:
- path = node.path
- return path in lf_paths
+ return node.path in lf_paths
res.result = sorted(
res.result,
key=sort_key,
reverse=True,
)
- return
elif isinstance(collector, File):
if collector.path in self.lfplugin._last_failed_paths:
- out = yield
- res = out.get_result()
result = res.result
lastfailed = self.lfplugin.lastfailed
# Only filter with known failures.
if not self._collected_at_least_one_failure:
if not any(x.nodeid in lastfailed for x in result):
- return
+ return res
self.lfplugin.config.pluginmanager.register(
LFPluginCollSkipfiles(self.lfplugin), "lfplugin-collskip"
)
@@ -268,8 +263,8 @@ class LFPluginCollWrapper:
# Keep all sub-collectors.
or isinstance(x, nodes.Collector)
]
- return
- yield
+
+ return res
class LFPluginCollSkipfiles:
@@ -280,9 +275,7 @@ class LFPluginCollSkipfiles:
def pytest_make_collect_report(
self, collector: nodes.Collector
) -> Optional[CollectReport]:
- # Packages are Files, but we only want to skip test-bearing Files,
- # so don't filter Packages.
- if isinstance(collector, File) and not isinstance(collector, Package):
+ if isinstance(collector, File):
if collector.path not in self.lfplugin._last_failed_paths:
self.lfplugin._skipped_files += 1
@@ -342,14 +335,14 @@ class LFPlugin:
else:
self.lastfailed[report.nodeid] = True
- @hookimpl(hookwrapper=True, tryfirst=True)
+ @hookimpl(wrapper=True, tryfirst=True)
def pytest_collection_modifyitems(
self, config: Config, items: List[nodes.Item]
) -> Generator[None, None, None]:
- yield
+ res = yield
if not self.active:
- return
+ return res
if self.lastfailed:
previously_failed = []
@@ -376,15 +369,13 @@ class LFPlugin:
noun = "failure" if self._previously_failed_count == 1 else "failures"
suffix = " first" if self.config.getoption("failedfirst") else ""
- self._report_status = "rerun previous {count} {noun}{suffix}".format(
- count=self._previously_failed_count, suffix=suffix, noun=noun
+ self._report_status = (
+ f"rerun previous {self._previously_failed_count} {noun}{suffix}"
)
if self._skipped_files > 0:
files_noun = "file" if self._skipped_files == 1 else "files"
- self._report_status += " (skipped {files} {files_noun})".format(
- files=self._skipped_files, files_noun=files_noun
- )
+ self._report_status += f" (skipped {self._skipped_files} {files_noun})"
else:
self._report_status = "no previously failed tests, "
if self.config.getoption("last_failed_no_failures") == "none":
@@ -394,6 +385,8 @@ class LFPlugin:
else:
self._report_status += "not deselecting items."
+ return res
+
def pytest_sessionfinish(self, session: Session) -> None:
config = self.config
if config.getoption("cacheshow") or hasattr(config, "workerinput"):
@@ -414,11 +407,11 @@ class NFPlugin:
assert config.cache is not None
self.cached_nodeids = set(config.cache.get("cache/nodeids", []))
- @hookimpl(hookwrapper=True, tryfirst=True)
+ @hookimpl(wrapper=True, tryfirst=True)
def pytest_collection_modifyitems(
self, items: List[nodes.Item]
) -> Generator[None, None, None]:
- yield
+ res = yield
if self.active:
new_items: Dict[str, nodes.Item] = {}
@@ -436,6 +429,8 @@ class NFPlugin:
else:
self.cached_nodeids.update(item.nodeid for item in items)
+ return res
+
def _get_increasing_order(self, items: Iterable[nodes.Item]) -> List[nodes.Item]:
return sorted(items, key=lambda item: item.path.stat().st_mtime, reverse=True) # type: ignore[no-any-return]