Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pytest assertion doesn't show differences on AssertionError

Tags:

python

pytest

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.

like image 659
Victor Cui Avatar asked Oct 26 '18 04:10

Victor Cui


1 Answers

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.

like image 72
kolis Avatar answered Sep 30 '22 04:09

kolis