@@ -377,3 +377,60 @@ def test_hash_missing(tmpdir):
377
377
# If we don't use --mpl option, the test should succeed
378
378
code = call_pytest ([test_file ])
379
379
assert code == 0
380
+
381
+
382
+ TEST_RESULTS_ALWAYS = """
383
+ import pytest
384
+ import matplotlib.pyplot as plt
385
+ def plot():
386
+ fig = plt.figure()
387
+ ax = fig.add_subplot(1,1,1)
388
+ ax.plot([1,2,2])
389
+ return fig
390
+ @pytest.mark.mpl_image_compare
391
+ def test_modified(): return plot()
392
+ @pytest.mark.mpl_image_compare
393
+ def test_new(): return plot()
394
+ @pytest.mark.mpl_image_compare
395
+ def test_unmodified(): return plot()
396
+ """
397
+
398
+
399
+ def test_results_always (tmpdir ):
400
+
401
+ test_file = tmpdir .join ('test.py' ).strpath
402
+ with open (test_file , 'w' ) as f :
403
+ f .write (TEST_RESULTS_ALWAYS )
404
+ results_path = tmpdir .mkdir ('results' )
405
+
406
+ code = call_pytest (['--mpl' , test_file , '--mpl-results-always' ,
407
+ rf'--mpl-hash-library={ hash_library } ' ,
408
+ rf'--mpl-baseline-path={ baseline_dir_abs } ' ,
409
+ '--mpl-generate-summary=html' ,
410
+ rf'--mpl-results-path={ results_path .strpath } ' ])
411
+ assert code == 0 # hashes correct, so all should pass
412
+
413
+ comparison_file = results_path .join ('fig_comparison.html' )
414
+ with open (comparison_file , 'r' ) as f :
415
+ html = f .read ()
416
+
417
+ # each test, and which images should exist
418
+ for test , exists in [
419
+ ('test_modified' , ['baseline' , 'result-failed-diff' , 'result' ]),
420
+ ('test_new' , ['result' ]),
421
+ ('test_unmodified' , ['baseline' , 'result' ]),
422
+ ]:
423
+
424
+ test_name = f'test.{ test } '
425
+
426
+ summary = f'{ test_name } (passed)'
427
+ assert summary in html
428
+
429
+ for image_type in ['baseline' , 'result-failed-diff' , 'result' ]:
430
+ image = f'{ test_name } /{ image_type } .png'
431
+ assert image in html # <img> is present even if 404
432
+ image_exists = results_path .join (* image .split ('/' )).exists ()
433
+ if image_type in exists :
434
+ assert image_exists
435
+ else :
436
+ assert not image_exists
0 commit comments