Skip to content

Commit e2cdacd

Browse files
committed
Some error ordering issues
1 parent 6a50d95 commit e2cdacd

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

pytest_mpl/plugin.py

+21-16
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ def __init__(self,
293293

294294
# We need global state to store all the hashes generated over the run
295295
self._generated_hash_library = {}
296+
self._test_results = {}
296297

297298
def get_compare(self, item):
298299
"""
@@ -506,28 +507,27 @@ def compare_image_to_hash_library(self, item, fig, result_dir):
506507
if not hash_comparison_pass and not self.baseline_directory_specified(item) or new_test:
507508
return error_message
508509

509-
# Get the baseline and generate a diff image, always so that
510-
# --mpl-results-always can be respected.
511-
# Ignore Errors here as it's possible the reference image dosen't exist yet.
512-
try:
513-
baseline_comparison = self.compare_image_to_baseline(item, fig, result_dir)
514-
except Exception as e:
515-
pass
516-
517-
# If the hash comparison passes then return
518-
if hash_comparison_pass:
519-
return
520-
521510
# If this is not a new test try and get the baseline image.
522511
if not new_test:
523-
baseline_image_path = self.obtain_baseline_image(item, result_dir)
512+
# Ignore Errors here as it's possible the reference image dosen't exist yet.
513+
try:
514+
baseline_image_path = self.obtain_baseline_image(item, result_dir)
515+
# Get the baseline and generate a diff image, always so that
516+
# --mpl-results-always can be respected.
517+
baseline_comparison = self.compare_image_to_baseline(item, fig, result_dir)
518+
except Exception as e:
519+
warnings.warn(str(e))
524520

525521
try:
526522
baseline_image = baseline_image_path
527523
baseline_image = None if (baseline_image and not baseline_image.exists()) else baseline_image
528524
except Exception:
529525
baseline_image = None
530526

527+
# If the hash comparison passes then return
528+
if hash_comparison_pass:
529+
return
530+
531531
if baseline_image is None:
532532
error_message += f"\nUnable to find baseline image {baseline_image_path or ''}."
533533
return error_message
@@ -581,6 +581,8 @@ def item_function_wrapper(*args, **kwargs):
581581
if remove_text:
582582
remove_ticks_and_titles(fig)
583583

584+
test_name = self.generate_test_name(item)
585+
584586
# What we do now depends on whether we are generating the
585587
# reference images or simply running the test.
586588
if self.generate_dir is not None:
@@ -589,8 +591,7 @@ def item_function_wrapper(*args, **kwargs):
589591
pytest.skip("Skipping test, since generating image.")
590592

591593
if self.generate_hash_library is not None:
592-
hash_name = self.generate_test_name(item)
593-
self._generated_hash_library[hash_name] = self.generate_image_hash(item, fig)
594+
self._generated_hash_library[test_name] = self.generate_image_hash(item, fig)
594595
pytest.skip("Skipping test as generating hash library.")
595596

596597
# Only test figures if we are not generating hashes or images
@@ -607,6 +608,8 @@ def item_function_wrapper(*args, **kwargs):
607608

608609
close_mpl_figure(fig)
609610

611+
self._test_results[str(pathify(test_name))] = msg or True
612+
610613
if msg is None:
611614
if not self.results_always:
612615
shutil.rmtree(result_dir)
@@ -629,8 +632,10 @@ def generate_summary_html(self, dir_list):
629632
f.write(HTML_INTRO)
630633

631634
for directory in dir_list:
635+
test_name = directory.parts[-1]
636+
test_result = 'passed' if self._test_results[test_name] is True else 'failed'
632637
f.write('<tr>'
633-
f'<td>{directory.parts[-1]}\n'
638+
f'<td>{test_name} ({test_result})\n'
634639
f'<td><img src="{directory / "baseline.png"}"></td>\n'
635640
f'<td><img src="{directory / "result-failed-diff.png"}"></td>\n'
636641
f'<td><img src="{directory / "result.png"}"></td>\n'

0 commit comments

Comments
 (0)