-
|
I have some objects of complex nested types which I would like to compare using snapshots. But these types also use |
Beta Was this translation helpful? Give feedback.
Answered by
Genfood
Oct 21, 2025
Replies: 1 comment
-
|
I wrote a custom matcher to sort the sets before parsing them. Here is a simple example: @dataclass
class TestA:
name: str
b: TestB
@dataclass
class TestB:
test_set: set[str]
def sort_sets_matcher(data: Any, path: tuple[Any, ...]) -> Any:
if isinstance(data, set):
return sorted(list(data))
if dataclasses.is_dataclass(data) and not isinstance(data, type):
# The serializer will walk this dict
return dataclasses.asdict(data)
return data
def test_my_dataclass(snapshot: SnapshotAssertion):
my_object = TestA(
name="Test Name",
b=TestB(
test_set={"c", "a", "z", "b"}
)
)
assert my_object == snapshot(matcher=custom_data_matcher)I think the problem wasnt the |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Genfood
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wrote a custom matcher to sort the sets before parsing them. Here is a simple example: