Skip to content

Commit

Permalink
fix: Example.run_pytest(raise=snapshot(...)) is now handled correct
Browse files Browse the repository at this point in the history
  • Loading branch information
15r10nk committed Nov 13, 2024
1 parent 0ad4ee3 commit 5b750dd
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
39 changes: 39 additions & 0 deletions changelog.d/20241113_170944_15r10nk-git_fixes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Removed
- A bullet item for the Removed category.
-->
<!--
### Added
- A bullet item for the Added category.
-->
<!--
### Changed
- A bullet item for the Changed category.
-->
<!--
### Deprecated
- A bullet item for the Deprecated category.
-->
### Fixed
- `Example(...).run_pytest(raise=snapshot(...))` uses now the flags from the current run and not the flags from the Example.

<!--
### Security
- A bullet item for the Security category.
-->
8 changes: 7 additions & 1 deletion src/inline_snapshot/testing/_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def run_inline(

self._write_files(tmp_path)

raised_exception = None
with snapshot_env():
with ChangeRecorder().activate() as recorder:
_inline_snapshot._update_flags = Flags({*flags})
Expand All @@ -160,7 +161,7 @@ def run_inline(
if k.startswith("test_") and callable(v):
v()
except Exception as e:
assert raises == f"{type(e).__name__}:\n" + str(e)
raised_exception = e

finally:
_inline_snapshot._active = False
Expand All @@ -182,6 +183,11 @@ def run_inline(
if reported_categories is not None:
assert sorted(snapshot_flags) == reported_categories

if raised_exception is not None:
assert raises == f"{type(raised_exception).__name__}:\n" + str(
raised_exception
)

recorder.fix_all()

if changed_files is not None:
Expand Down

0 comments on commit 5b750dd

Please sign in to comment.