@@ -411,3 +411,60 @@ def test_hash_missing(tmpdir):
411
411
# If we don't use --mpl option, the test should succeed
412
412
code = call_pytest ([test_file ])
413
413
assert code == 0
414
+
415
+
416
+ TEST_RESULTS_ALWAYS = """
417
+ import pytest
418
+ import matplotlib.pyplot as plt
419
+ def plot():
420
+ fig = plt.figure()
421
+ ax = fig.add_subplot(1,1,1)
422
+ ax.plot([1,2,2])
423
+ return fig
424
+ @pytest.mark.mpl_image_compare
425
+ def test_modified(): return plot()
426
+ @pytest.mark.mpl_image_compare
427
+ def test_new(): return plot()
428
+ @pytest.mark.mpl_image_compare
429
+ def test_unmodified(): return plot()
430
+ """
431
+
432
+
433
+ def test_results_always (tmpdir ):
434
+
435
+ test_file = tmpdir .join ('test.py' ).strpath
436
+ with open (test_file , 'w' ) as f :
437
+ f .write (TEST_RESULTS_ALWAYS )
438
+ results_path = tmpdir .mkdir ('results' )
439
+
440
+ code = call_pytest (['--mpl' , test_file , '--mpl-results-always' ,
441
+ rf'--mpl-hash-library={ hash_library } ' ,
442
+ rf'--mpl-baseline-path={ baseline_dir_abs } ' ,
443
+ '--mpl-generate-summary=html' ,
444
+ rf'--mpl-results-path={ results_path .strpath } ' ])
445
+ assert code == 0 # hashes correct, so all should pass
446
+
447
+ comparison_file = results_path .join ('fig_comparison.html' )
448
+ with open (comparison_file , 'r' ) as f :
449
+ html = f .read ()
450
+
451
+ # each test, and which images should exist
452
+ for test , exists in [
453
+ ('test_modified' , ['baseline' , 'result-failed-diff' , 'result' ]),
454
+ ('test_new' , ['result' ]),
455
+ ('test_unmodified' , ['baseline' , 'result' ]),
456
+ ]:
457
+
458
+ test_name = f'test.{ test } '
459
+
460
+ summary = f'{ test_name } (passed)'
461
+ assert summary in html
462
+
463
+ for image_type in ['baseline' , 'result-failed-diff' , 'result' ]:
464
+ image = f'{ test_name } /{ image_type } .png'
465
+ assert image in html # <img> is present even if 404
466
+ image_exists = results_path .join (* image .split ('/' )).exists ()
467
+ if image_type in exists :
468
+ assert image_exists
469
+ else :
470
+ assert not image_exists
0 commit comments