@@ -51,6 +51,8 @@ def assert_pytest_fails_with(args, output_substring):
51
51
output = exc .output .decode ()
52
52
assert output_substring in output , output
53
53
return output
54
+ else :
55
+ raise RuntimeError (f'pytest did not fail with args { args } ' )
54
56
55
57
56
58
@pytest .mark .mpl_image_compare (baseline_dir = baseline_dir_local ,
@@ -187,10 +189,10 @@ def test_generate(tmpdir):
187
189
assert code == 0
188
190
assert os .path .exists (os .path .join (gen_dir , 'test_gen.png' ))
189
191
190
- # If we do generate hash, the test should succeed and a new file will appear
192
+ # If we do generate hash, the test will fail as no image is present
191
193
hash_file = os .path .join (gen_dir , 'test_hashes.json' )
192
194
code = call_pytest ([f'--mpl-generate-hash-library={ hash_file } ' , test_file ])
193
- assert code == 0
195
+ assert code == 1
194
196
assert os .path .exists (hash_file )
195
197
196
198
with open (hash_file ) as fp :
@@ -348,6 +350,38 @@ def test_hash_fail_hybrid(tmpdir):
348
350
assert code == 0
349
351
350
352
353
+ TEST_FAILING_NEW_HASH = r"""
354
+ import pytest
355
+ import matplotlib.pyplot as plt
356
+ @pytest.mark.mpl_image_compare
357
+ def test_hash_fails():
358
+ fig = plt.figure()
359
+ ax = fig.add_subplot(1,1,1)
360
+ ax.plot([1,2,2])
361
+ return fig
362
+ """
363
+
364
+
365
+ @pytest .mark .skipif (ftv != '261' , reason = "Incorrect freetype version for hash check" )
366
+ def test_hash_fail_new_hashes (tmpdir ):
367
+ # Check that the hash comparison fails even if a new hash file is requested
368
+ test_file = tmpdir .join ('test.py' ).strpath
369
+ with open (test_file , 'w' , encoding = 'ascii' ) as f :
370
+ f .write (TEST_FAILING_NEW_HASH )
371
+
372
+ # Assert that image comparison runs and fails
373
+ assert_pytest_fails_with (['--mpl' , test_file ,
374
+ f'--mpl-hash-library={ fail_hash_library } ' ],
375
+ "doesn't match hash FAIL in library" )
376
+
377
+ hash_file = tmpdir .join ('new_hashes.json' ).strpath
378
+ # Assert that image comparison runs and fails
379
+ assert_pytest_fails_with (['--mpl' , test_file ,
380
+ f'--mpl-hash-library={ fail_hash_library } ' ,
381
+ f'--mpl-generate-hash-library={ hash_file } ' ],
382
+ "doesn't match hash FAIL" )
383
+
384
+
351
385
TEST_MISSING_HASH = """
352
386
import pytest
353
387
import matplotlib.pyplot as plt
0 commit comments