From 9f06f9ad48cfdd9964b2546421148c8a513f7039 Mon Sep 17 00:00:00 2001 From: Frank Hoffmann <15r10nk-git@polarbit.de> Date: Wed, 30 Oct 2024 20:27:44 +0100 Subject: [PATCH] fix: Example.run_pytest(raise=snapshot(...)) is now handled correct --- src/inline_snapshot/testing/_example.py | 10 +++++++--- tests/test_dirty_equals.py | 6 +++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/inline_snapshot/testing/_example.py b/src/inline_snapshot/testing/_example.py index c821033d..034ee8a0 100644 --- a/src/inline_snapshot/testing/_example.py +++ b/src/inline_snapshot/testing/_example.py @@ -5,7 +5,6 @@ import platform import re import subprocess as sp -import traceback from argparse import ArgumentParser from pathlib import Path from tempfile import TemporaryDirectory @@ -146,6 +145,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}) @@ -167,8 +167,7 @@ def run_inline( if k.startswith("test_") and callable(v): v() except Exception as e: - print(traceback.format_exc()) - assert raises == f"{type(e).__name__}:\n" + str(e) + raised_exception = e finally: _inline_snapshot._active = False @@ -190,6 +189,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: diff --git a/tests/test_dirty_equals.py b/tests/test_dirty_equals.py index 49dda8d3..a256c38f 100644 --- a/tests/test_dirty_equals.py +++ b/tests/test_dirty_equals.py @@ -2,7 +2,7 @@ from inline_snapshot.testing._example import Example -def test_dirty_equals(): +def test_dirty_equals_repr(): Example( """\ from inline_snapshot import snapshot @@ -20,8 +20,8 @@ def test_something(): inline-snapshot uses `copy.deepcopy` to copy objects, but the copied object is not equal to the original one: -original: HasRepr(list, '[]') -copied: HasRepr(list, '[]') +original: [HasRepr(IsStr, '< type(obj) can not be compared with == >')] +copied: [HasRepr(IsStr, '< type(obj) can not be compared with == >')] Please fix the way your object is copied or your __eq__ implementation. """