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

When a snapshot test is marked with skip or skipif syrupy exits with a failure exit code #842

Open
rodrigogiraoserrao opened this issue Dec 13, 2023 · 2 comments · May be fixed by #862
Open

Comments

@rodrigogiraoserrao
Copy link

Describe the bug

If a snapshot test is skipped because it was marked with pytest.mark.skip or with pytest.mark.skipif, syrupy will:

  • correctly report that the related snapshots were unused; but
  • incorrectly report a failed test run.

To reproduce

Mark a test with pytest.mark.skip.

Expected behavior

The test run shouldn't terminate with an error.
(It's ok that the snapshots that weren't used because the tests were skipped are reported as unused, but that currently happens with a red [error] message.
It would potentially make sense to count skipped tests separately from truly unused ones...)

Screenshots

Environment (please complete the following information):

  • OS: MacOS Sonoma 14.0 (23A344)
  • Syrupy Version: tested with 3.0.9 & 4.6.0
  • Python Version: 3.12

Additional context

We have some snapshot tests that can only run on Python versions below 3.12, so we'd like to skip some snapshot tests if the Python version is 3.12.

@zzzachzzz
Copy link

zzzachzzz commented Jan 26, 2024

You can use the --snapshot-warn-unused option to warn instead of error, resulting in an exit code of 0 (assuming all tests pass). You can make this option an automatic default when running pytest by specifying it in a pytest.ini file:

[pytest]
addopts = --snapshot-warn-unused

I do have some gripes with how snapshots interact with skipped tests. I have a test relying on an external api request whose results I snapshot. I mark this test to be skipped because I only wish to run this test occasionally to test my integration with said external api. There's a couple problems:

  1. The problem outlined in the original issue (okay whatever, we can workaround it with --snapshot-warn-unused)
  2. When I perform a snapshot update with --snapshot-update, because I have a snapshot corresponding to a skipped test, syrupy deletes the snapshot, since it has been identified as "unused". Any suggested workarounds for this issue would be appreciated.

Edit Just found issue #787 which is my problem 2 ^

@AllanChain AllanChain linked a pull request Mar 22, 2024 that will close this issue
3 tasks
@ddorian
Copy link

ddorian commented Mar 23, 2024

I mark this test to be skipped because I only wish to run this test occasionally to test my integration with said external API.

Maybe you can use pytest-recording to cache the response?

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 a pull request may close this issue.

3 participants