Skip to content

Commit

Permalink
snapshots inside tests which are marked as xfail are now ignored (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Feb 11, 2025
1 parent 515f76e commit aaf3ef6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
3 changes: 3 additions & 0 deletions changelog.d/20250202_081752_15r10nk-git_new_defaults.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### Fixed

- snapshots inside tests which are marked as xfail are now ignored (#184)
12 changes: 10 additions & 2 deletions src/inline_snapshot/pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from ._code_repr import used_hasrepr
from ._find_external import ensure_import
from ._flags import Flags
from ._global_state import snapshot_env
from ._global_state import state
from ._inline_snapshot import used_externals
from ._rewrite_code import ChangeRecorder
Expand Down Expand Up @@ -149,10 +150,17 @@ def pytest_configure(config):


@pytest.fixture(autouse=True)
def snapshot_check():
def snapshot_check(request):
state().missing_values = 0
state().incorrect_values = 0
yield

if "xfail" in request.keywords:
with snapshot_env() as local_state:
local_state.active = False
yield
return
else:
yield

missing_values = state().missing_values
incorrect_values = state().incorrect_values
Expand Down
19 changes: 19 additions & 0 deletions tests/test_pytest_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,3 +795,22 @@ def test_something():
}
),
)


def test_xfail():

Example(
"""\
import pytest
@pytest.mark.xfail
def test_a():
assert 1==snapshot(5)
"""
).run_pytest(
["--inline-snapshot=fix"],
report=snapshot(""),
returncode=snapshot(0),
stderr=snapshot(""),
changed_files=snapshot({}),
)

0 comments on commit aaf3ef6

Please sign in to comment.