Skip to content

Commit 9a9378f

Browse files
committed
fix: pytest_assertrepr_compare should be a no-op for other types
If neither operand is a `SnapshotAssertion` then the rest of the code is not going to do anything, so bail early rather than unnecessarily setting up `__terminal_color` etc. which can cause issues c.f. syrupy-project#955
1 parent 7f7f6dd commit 9a9378f

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/syrupy/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ def pytest_assertrepr_compare(
123123
Return explanation for comparisons in failing assert expressions.
124124
https://docs.pytest.org/en/latest/reference.html#_pytest.hookspec.pytest_assertrepr_compare
125125
"""
126+
if not isinstance(left, SnapshotAssertion) and not isinstance(right, SnapshotAssertion):
127+
# Shortcut to minimise overhead in the case of other unrelated assertions
128+
return None
129+
126130
with __terminal_color(config):
127131
received_name = received_style("[+ received]")
128132

0 commit comments

Comments
 (0)