When using pytest
, I get nice pretty printing when two objects are not equivalent:
Expected :Foo(id='red', other_thing='green')
Actual :Foo(id='red', other_thing='blue')
<Click to see difference>
def test_baz():
oneFoo = Foo(id="red", other_thing="blue")
twoFoo = Foo(id="red", other_thing="green")
> assert oneFoo == twoFoo
E AssertionError: assert Foo(id='red', other_thing='blue') == Foo(id='red', other_thing='green')
E
E Full diff:
E - Foo(id='red', other_thing='green')
E ? ^^ --
E + Foo(id='red', other_thing='blue')
E ? ^^^
baz.py:22: AssertionError
If I use an assert directly in my code, I just get an AssertionError
and a stacktrace.
I am writing some integration tests right now that are NOT driven by pytest but would like to pretty print when two items (specifically Pydantic dataclasses) are not equal.