Skip to content

Commit ea3cffc

Browse files
committed
Some error ordering issues
1 parent 7fdcce6 commit ea3cffc

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

pytest_mpl/plugin.py

+25-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
"""
@@ -504,28 +505,27 @@ def compare_image_to_hash_library(self, item, fig, result_dir):
504505
if not hash_comparison_pass and not self.baseline_directory_specified(item) or new_test:
505506
return error_message
506507

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

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

525+
# If the hash comparison passes then return
526+
if hash_comparison_pass:
527+
return
528+
529529
if baseline_image is None:
530530
error_message += f"\nUnable to find baseline image {baseline_image_path or ''}."
531531
return error_message
@@ -579,6 +579,8 @@ def item_function_wrapper(*args, **kwargs):
579579
if remove_text:
580580
remove_ticks_and_titles(fig)
581581

582+
test_name = self.generate_test_name(item)
583+
582584
# What we do now depends on whether we are generating the
583585
# reference images or simply running the test.
584586
if self.generate_dir is not None:
@@ -587,8 +589,7 @@ def item_function_wrapper(*args, **kwargs):
587589
pytest.skip("Skipping test, since generating image.")
588590

589591
if self.generate_hash_library is not None:
590-
hash_name = self.generate_test_name(item)
591-
self._generated_hash_library[hash_name] = self.generate_image_hash(item, fig)
592+
self._generated_hash_library[test_name] = self.generate_image_hash(item, fig)
592593
pytest.skip("Skipping test as generating hash library.")
593594

594595
# Only test figures if we are not generating hashes or images
@@ -605,6 +606,8 @@ def item_function_wrapper(*args, **kwargs):
605606

606607
close_mpl_figure(fig)
607608

609+
self._test_results[str(pathify(test_name))] = msg or True
610+
608611
if msg is None:
609612
if not self.results_always:
610613
shutil.rmtree(result_dir)
@@ -627,8 +630,14 @@ def generate_summary_html(self, dir_list):
627630
f.write(HTML_INTRO)
628631

629632
for directory in dir_list:
633+
test_name = directory.parts[-1]
634+
if test_name not in self._test_results:
635+
breakpoint()
636+
test_result = 'no baseline image'
637+
else:
638+
test_result = 'passed' if self._test_results[test_name] is True else 'failed'
630639
f.write('<tr>'
631-
f'<td>{directory.parts[-1]}\n'
640+
f'<td>{test_name} ({test_result})\n'
632641
f'<td><img src="{directory / "baseline.png"}"></td>\n'
633642
f'<td><img src="{directory / "result-failed-diff.png"}"></td>\n'
634643
f'<td><img src="{directory / "result.png"}"></td>\n'

0 commit comments

Comments
 (0)