Skip to content

cacheprovider: speed up NFPlugin when --nf is not enabled #7130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions src/_pytest/cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,13 @@ class NFPlugin:
def __init__(self, config):
self.config = config
self.active = config.option.newfirst
self.cached_nodeids = config.cache.get("cache/nodeids", [])
self.cached_nodeids = set(config.cache.get("cache/nodeids", []))

def pytest_collection_modifyitems(
self, session: Session, config: Config, items: List[nodes.Item]
) -> None:
new_items = OrderedDict() # type: OrderedDict[str, nodes.Item]
if self.active:
new_items = OrderedDict() # type: OrderedDict[str, nodes.Item]
other_items = OrderedDict() # type: OrderedDict[str, nodes.Item]
for item in items:
if item.nodeid not in self.cached_nodeids:
Expand All @@ -349,11 +349,9 @@ def pytest_collection_modifyitems(
items[:] = self._get_increasing_order(
new_items.values()
) + self._get_increasing_order(other_items.values())
self.cached_nodeids.update(new_items)
else:
for item in items:
if item.nodeid not in self.cached_nodeids:
new_items[item.nodeid] = item
self.cached_nodeids.extend(new_items)
self.cached_nodeids.update(item.nodeid for item in items)

def _get_increasing_order(self, items):
return sorted(items, key=lambda item: item.fspath.mtime(), reverse=True)
Expand All @@ -363,7 +361,7 @@ def pytest_sessionfinish(self, session):
if config.getoption("cacheshow") or hasattr(config, "slaveinput"):
return

config.cache.set("cache/nodeids", self.cached_nodeids)
config.cache.set("cache/nodeids", sorted(self.cached_nodeids))


def pytest_addoption(parser):
Expand Down
2 changes: 1 addition & 1 deletion testing/test_cacheprovider.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_cache_failure_warns(self, testdir, monkeypatch):
"*/cacheprovider.py:*",
" */cacheprovider.py:*: PytestCacheWarning: could not create cache path "
"{}/v/cache/nodeids".format(cache_dir),
' config.cache.set("cache/nodeids", self.cached_nodeids)',
' config.cache.set("cache/nodeids", sorted(self.cached_nodeids))',
"*1 failed, 3 warnings in*",
]
)
Expand Down