Skip to content
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

KeyError during report generation in syrupy when pytest is also doing doctests #451

Closed
daphtdazz opened this issue Dec 11, 2020 · 5 comments · Fixed by #549
Closed

KeyError during report generation in syrupy when pytest is also doing doctests #451

daphtdazz opened this issue Dec 11, 2020 · 5 comments · Fixed by #549
Labels
bug Something isn't working released

Comments

@daphtdazz
Copy link

Describe the bug

Errors such as

735    PyTestLocation(item).matches_snapshot_name(snapshot_name)
736  File "/app/.venv/lib64/python3.6/site-packages/syrupy/report.py", line 171, in <genexpr>
737    if self.selected_items[nodeid]
738 KeyError: 'path/to/doctest.py::path.to.doctest.MyClass.doctest'

To reproduce

Will try and provide for a test, but I will push a patch shortly since I know what the issue is. It also doesn't seem to be deterministic because it depends on ordering in a set object (I think).

Expected behavior

Not to crash during report generation.

Screenshots

N/A

Environment (please complete the following information):

  • OS: Mac OSX Catalina
  • Syrupy Version: 1.1.0
  • Python Version: 3.7

Additional context

@daphtdazz daphtdazz changed the title KeyError during report generation in syrupy when pytest is also doing doctests KeyError during report generation in syrupy when pytest is also doing doctests Dec 11, 2020
@daphtdazz
Copy link
Author

Incidentally I'm pretty sure this was introduced by this fix for my previous issue!

@daphtdazz
Copy link
Author

The patch that I'm doing locally (and I will push an MR soon, but maybe not today...) is:

from syrupy.session import SnapshotSession


real_ran_item = SnapshotSession.ran_item

def patched_ran_item(self, nodeid):
    # Issue
    if nodeid not in self._selected_items:
        return
    real_ran_item(self, nodeid)

SnapshotSession.ran_item = patched_ran_item

The problem is that SnapshotSession.filter_valid_items() was called when setting _selected_items but then we update _selected_items in SnapshotReport.ran_items(), without checking whether we were supposed to have selected it.

@noahnu noahnu added the bug Something isn't working label Dec 11, 2020
@noahnu
Copy link
Collaborator

noahnu commented Jun 11, 2021

@daphtdazz Is this still an issue?

@daphtdazz
Copy link
Author

Sorry for delay, yes it still is in 1.3.1.

tophat-opensource-bot pushed a commit that referenced this issue Aug 29, 2021
## [1.4.5](v1.4.4...v1.4.5) (2021-08-29)

### Bug Fixes

* filter ran items using selected items, close [#451](#451) ([#549](#549)) ([7374862](7374862))
@tophat-opensource-bot
Copy link
Contributor

🎉 This issue has been resolved in version 1.4.5 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants