Skip to content

cacheprovider: pytest_collection_modifyitems: copy items #6411

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
Jan 9, 2020

Conversation

blueyed
Copy link
Contributor

@blueyed blueyed commented Jan 6, 2020

Noticed this with #6409, where items is stored/used as-is when there are no "deselected" stats yet.

@@ -258,7 +258,7 @@ def pytest_collection_modifyitems(self, session, config, items):
self._report_status = "no previously failed tests, "
if self.config.getoption("last_failed_no_failures") == "none":
self._report_status += "deselecting all items."
config.hook.pytest_deselected(items=items)
config.hook.pytest_deselected(items=items[:])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

I wonder if it is a cache provider bug though... I mean, should every caller of pytest_deselected(items) always send a copy over? 🤔

Sure, pytest_deselected is kind of a weird hook, but I thought I would raise this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure myself, but here it is clear that the list is cleared just below at least.

FWIW, I've found an issue with auto-deselecting of tests when I was passing a set there (and trying to items[:] it).
As for the terminal plugin only the length is relevant anyway I think (#6409), but thought to keep stats there like before.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for sanity we should actually fail if session.items is passed by accident

this is a great and horrifying catch

the typical/presumed usage is collecting keep and drop in new lists, then passing drop after changing items, so the error is a honest misstake

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RonnyPfannschmidt

for sanity we should actually fail if session.items is passed by accident

Makes sense, please consider creating a new issue for it.

the typical/presumed usage is collecting keep and drop in new lists, then passing drop after changing items, so the error is a honest misstake

I could not really parse this.

blueyed added a commit to blueyed/pytest that referenced this pull request Jan 7, 2020
@blueyed blueyed force-pushed the cacheprovider-copy-items branch from 54b9938 to 2d2c67d Compare January 9, 2020 20:49
@blueyed blueyed closed this Jan 9, 2020
@blueyed blueyed reopened this Jan 9, 2020
@blueyed blueyed merged commit 9f1ade9 into pytest-dev:features Jan 9, 2020
@blueyed blueyed deleted the cacheprovider-copy-items branch January 9, 2020 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants