Skip to content

Commit febed7d

Browse files
committed
Display relative image paths when tests fail.
Before the PR, an image comparison failure was reported as ``` E matplotlib.testing.exceptions.ImageComparisonFailure: images not close: /home/antony/src/extern/matplotlib/result_images/test_axes/pcolormesh_svg.png vs. /home/antony/src/extern/matplotlib/result_images/test_axes/pcolormesh-expected_svg.png (RMS 0.001) ``` This PR changes it to ``` E matplotlib.testing.exceptions.ImageComparisonFailure: images not close (RMS 0.001): E result_images/test_axes/pcolormesh_svg.png E result_images/test_axes/pcolormesh-expected_svg.png ``` which I believe more legible. (It would be nice to just display a single path but parts of the testing machinery seem to accept arbitrary image paths, not necessarily in the same folder, even though this is not done in practice.)
1 parent 70831bd commit febed7d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/matplotlib/testing/decorators.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,11 @@ def _raise_on_image_difference(expected, actual, tol):
203203
raise ImageComparisonFailure('image does not exist: %s' % expected)
204204

205205
if err:
206+
for key in ["actual", "expected"]:
207+
err[key] = os.path.relpath(err[key])
206208
raise ImageComparisonFailure(
207-
'images not close: %(actual)s vs. %(expected)s '
208-
'(RMS %(rms).3f)' % err)
209+
'images not close (RMS %(rms).3f):\n\t%(actual)s\n\t%(expected)s '
210+
% err)
209211

210212

211213
def _xfail_if_format_is_uncomparable(extension):

0 commit comments

Comments
 (0)