Skip to content

Commit 4c3c724

Browse files
authored
Merge pull request #12537 from timhoffm/pyplot-test-message
Improve error message on failing test_pyplot_up_to_date
2 parents 6dfbfd8 + b4fc581 commit 4c3c724

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/matplotlib/tests/test_pyplot.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import difflib
12
import subprocess
23
import sys
34
from pathlib import Path
@@ -16,7 +17,21 @@ def test_pyplot_up_to_date():
1617
try:
1718
subprocess.run([sys.executable, str(gen_script)], check=True)
1819
new_contents = Path(plt.__file__).read_text()
19-
assert orig_contents == new_contents
20+
21+
if orig_contents != new_contents:
22+
diff_msg = '\n'.join(
23+
difflib.unified_diff(
24+
orig_contents.split('\n'), new_contents.split('\n'),
25+
fromfile='found pyplot.py',
26+
tofile='expected pyplot.py',
27+
n=0, lineterm=''))
28+
pytest.fail(
29+
"pyplot.py is not up-to-date. Please run "
30+
"'python tools/boilerplate.py' to update pyplot.py. "
31+
"This needs to be done from an environment where your "
32+
"current working copy is installed (e.g. 'pip install -e'd). "
33+
"Here is a diff of unexpected differences:\n%s" % diff_msg
34+
)
2035
finally:
2136
Path(plt.__file__).write_text(orig_contents)
2237

0 commit comments

Comments
 (0)