Skip to content

Commit

Permalink
cache: NFPlugin: keep known nodeids
Browse files Browse the repository at this point in the history
Caveat: does not forget about old nodeids

Fixes pytest-dev#5206
  • Loading branch information
blueyed committed Oct 19, 2019
1 parent c7eeb05 commit 73963aa
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions changelog/5206.bugfix.rst
@@ -0,0 +1 @@
Fix ``--nf`` to not forget about known nodeids with partial test selection.
8 changes: 6 additions & 2 deletions src/_pytest/cacheprovider.py
Expand Up @@ -264,8 +264,8 @@ def __init__(self, config):
self.cached_nodeids = config.cache.get("cache/nodeids", [])

def pytest_collection_modifyitems(self, session, config, items):
new_items = OrderedDict()
if self.active:
new_items = OrderedDict()
other_items = OrderedDict()
for item in items:
if item.nodeid not in self.cached_nodeids:
Expand All @@ -276,7 +276,11 @@ def pytest_collection_modifyitems(self, session, config, items):
items[:] = self._get_increasing_order(
new_items.values()
) + self._get_increasing_order(other_items.values())
self.cached_nodeids = [x.nodeid for x in items if isinstance(x, pytest.Item)]
else:
for item in items:
if item.nodeid not in self.cached_nodeids:
new_items[item.nodeid] = item
self.cached_nodeids.extend(new_items)

def _get_increasing_order(self, items):
return sorted(items, key=lambda item: item.fspath.mtime(), reverse=True)
Expand Down
7 changes: 6 additions & 1 deletion testing/test_cacheprovider.py
Expand Up @@ -982,8 +982,13 @@ def test_1(num): assert num
)
testdir.tmpdir.join("test_1/test_1.py").setmtime(1)

result = testdir.runpytest("-v", "--nf")
# Running only a subset does not forget about existing ones.
result = testdir.runpytest("-v", "--nf", "test_2/test_2.py")
result.stdout.fnmatch_lines(
["*test_2/test_2.py::test_1[1*", "*test_2/test_2.py::test_1[2*"]
)

result = testdir.runpytest("-v", "--nf")
result.stdout.fnmatch_lines(
[
"*test_1/test_1.py::test_1[3*",
Expand Down

0 comments on commit 73963aa

Please sign in to comment.