python - PyCharm show full diff when unittest fails for multiline string? -


i writing python unit tests using "unittest" framework , run them in pycharm. of tests compare long generated string reference value read file. if comparison fails, see diff of 2 compared strings using pycharms diff viewer.

so the code this:

    actual = open("actual.csv").read()     expected = pkg_resources.resource_string('my_package', 'expected.csv').decode('utf8')     self.assertmultilineequal(actual, expected) 

and pycharm nicely identifies test failure , provides link in results window click opens diff viewer. however, due how unittest shortens results, results such in diff viewer:

left side:

'time[57 chars]ercent 0;1;1;1;1;1;1;1 0;2;1;3;4;2;3;1 0;3;[110 chars]32 '

right side:

'time[57 chars]ercen 0;1;1;1;1;1;1;1 0;2;1;3;4;2;3;1 0;3;2[109 chars]32 '

now, rid of [x chars] parts , see whole file(s) , actual diff visualized pycharm.

i tried unittest code not find configuration option print full results. there variables such maxdiff , _diffthreshold have no impact on print.

also, tried run in py.test there support in pycharm less (no links failed test).

is there trick using difflib unittest or maybe other tricks python test framework this?

well, managed hack myself around test purposes. instead of using assertequal method unittest, wrote own , use inside unittest test cases. on failure, gives me full texts , pycharm diff viewer shows full diff correctly.

my assert statement in module of own (t_assert.py), , looks this

def equal(expected, actual):     msg = "'"+actual+"' != '"+expected+"'"     assert expected == actual, msg 

in test call this

    def test_example(self):         actual = open("actual.csv").read()         expected = pkg_resources.resource_string('my_package', 'expected.csv').decode('utf8')         t_assert.equal(expected, actual)         #self.assertequal(expected, actual) 

seems work far..


Comments