Victor Cui
Victor Cui

Reputation: 1705

Pytest assertion doesn't show differences on AssertionError

I recently learned about using Pytest for doing unit tests in Python. I've played around with it in Repl.it by doing a simple assertion on two different strings which should fail.

import pytest
assert 'a' == 'b'

Which fails with the error Traceback (most recent call last): File "python", line 2, in <module> AssertionError

However Pytest does not print 'a' or 'b'. This would be really helpful in debugging as I can compare the diff between 2 different strings. The unittest module has this feature by default. Does Pytest have this feature? If not how do I enable it? I'm using Pytest for a larger project and would love to figure this out before continuing work.

Upvotes: 11

Views: 7343

Answers (1)

kolis
kolis

Reputation: 574

Also see assertion rewriting if your assertion code is in an external helper function.

This was an issue for me, but fixed by adding pytest.register_assert_rewrite('path.to.helper') in the __init__.py in the test directory.

Upvotes: 16

Related Questions