Skip to content

Commit 2d2c67d

Browse files
committed
cacheprovider: pytest_collection_modifyitems: copy items
1 parent e8c8559 commit 2d2c67d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/_pytest/cacheprovider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ def pytest_collection_modifyitems(self, session, config, items):
258258
self._report_status = "no previously failed tests, "
259259
if self.config.getoption("last_failed_no_failures") == "none":
260260
self._report_status += "deselecting all items."
261-
config.hook.pytest_deselected(items=items)
261+
config.hook.pytest_deselected(items=items[:])
262262
items[:] = []
263263
else:
264264
self._report_status += "not deselecting items."

testing/test_cacheprovider.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,11 +681,28 @@ def test_2(): pass
681681
result.stdout.fnmatch_lines(["*2 passed*"])
682682
result = testdir.runpytest("--lf", "--lfnf", "all")
683683
result.stdout.fnmatch_lines(["*2 passed*"])
684+
685+
# Ensure the list passed to pytest_deselected is a copy,
686+
# and not a reference which is cleared right after.
687+
testdir.makeconftest(
688+
"""
689+
deselected = []
690+
691+
def pytest_deselected(items):
692+
global deselected
693+
deselected = items
694+
695+
def pytest_sessionfinish():
696+
print("\\ndeselected={}".format(len(deselected)))
697+
"""
698+
)
699+
684700
result = testdir.runpytest("--lf", "--lfnf", "none")
685701
result.stdout.fnmatch_lines(
686702
[
687703
"collected 2 items / 2 deselected",
688704
"run-last-failure: no previously failed tests, deselecting all items.",
705+
"deselected=2",
689706
"* 2 deselected in *",
690707
]
691708
)

0 commit comments

Comments
 (0)