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

Unused snapshot falsely detected when tests have same names #529

Closed
daphtdazz opened this issue Jul 28, 2021 · 3 comments · Fixed by #531
Closed

Unused snapshot falsely detected when tests have same names #529

daphtdazz opened this issue Jul 28, 2021 · 3 comments · Fixed by #531
Labels
bug Something isn't working released

Comments

@daphtdazz
Copy link

Describe the bug

If a test in one test file has the same name as a test in another test file, and both try to do a snapshot, if we run pytest but deselect one of those tests then pytest fails erroneously saying that a snapshot is obsolete.

To reproduce

Create two test files (test_a.py and test_b.py) with the following contents:

def test_name(snapshot):
    assert snapshot == [1, 2, 3]


def test_other():
    assert True

Create the snapshots:

pytest --snapshot-update test_a.py test_b.py

Attempt to run all but test_b.py::test_name:

pytest test_a.py test_b.py::test_other

Result: pytest exits with status 1 saying:

--------------------------- snapshot report summary ---------------------------
1 snapshot passed. 1 snapshot unused.

Re-run pytest with --snapshot-update to delete unused snapshots.

Expected behavior

pytest should exit successfully and we shouldn't be told a snapshot is unused, because we didn't run the test that used it.

Screenshots

Should be clear from above.

Environment (please complete the following information):

  • OS: several (macOS, Linux)
  • Syrupy Version: 1.3.1
  • Python Version: 3.6 and 3.7 (and I assume all the others)

Additional context

None

@noahnu
Copy link
Collaborator

noahnu commented Aug 2, 2021

Thanks for reporting this issue.

I have a fix in #531, just validating the correctness.

@noahnu
Copy link
Collaborator

noahnu commented Aug 4, 2021

Unfortunately my first attempt didn't work. This is difficult since we make no assumptions around the extension being used (ambr vs. another extension). I've updated my PR with some more test coverage which has at least given me confidence that my first approach doesn't work. I'll give this some more thought.

tophat-opensource-bot pushed a commit that referenced this issue Aug 18, 2021
## [1.4.1](v1.4.0...v1.4.1) (2021-08-18)

### Bug Fixes

* unused snapshot not filtered out when tests have similar names, close [#529](#529) ([#531](#531)) ([d0c8ca8](d0c8ca8))
@tophat-opensource-bot
Copy link
Contributor

🎉 This issue has been resolved in version 1.4.1 🎉

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