Skip to content

Commit 24ba2aa

Browse files
committed
Fix status reporting bug when remote baseline missing
This fixes a bug where, when in hybrid mode, a missing baseline image was not being recorded in the status report. This change makes the code process a baseline download failure similar to how it processes a missing local baseline file.
1 parent 4ec9cbb commit 24ba2aa

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

pytest_mpl/plugin.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,8 @@ def _download_file(self, baseline, filename):
398398
self.logger.info(f'Downloading {base_url + filename} failed: {repr(e)}')
399399
else:
400400
break
401-
else:
402-
raise Exception("Could not download baseline image from any of the "
403-
"available URLs")
401+
else: # Could not download baseline image from any of the available URLs
402+
return
404403
result_dir = Path(tempfile.mkdtemp())
405404
filename = result_dir / 'downloaded'
406405
with open(str(filename), 'wb') as tmpfile:
@@ -471,8 +470,6 @@ def compare_image_to_baseline(self, item, fig, result_dir, summary=None):
471470

472471
ext = self._file_extension(item)
473472

474-
baseline_image_ref = self.obtain_baseline_image(item)
475-
476473
test_image = (result_dir / f"result.{ext}").absolute()
477474
self.save_figure(item, fig, test_image)
478475

@@ -481,11 +478,20 @@ def compare_image_to_baseline(self, item, fig, result_dir, summary=None):
481478
else:
482479
summary['result_image'] = (result_dir / f"result_{ext}.png").relative_to(self.results_dir).as_posix()
483480

484-
if not os.path.exists(baseline_image_ref):
481+
baseline_image_ref = self.obtain_baseline_image(item)
482+
483+
baseline_missing = None
484+
if baseline_image_ref is None:
485+
baseline_missing = ("Could not download the baseline image from "
486+
"any of the available URLs.\n")
487+
elif not os.path.exists(baseline_image_ref):
488+
baseline_missing = ("Image file not found for comparison test in: \n\t"
489+
f"{self.get_baseline_directory(item)}\n")
490+
491+
if baseline_missing:
485492
summary['status'] = 'failed'
486493
summary['image_status'] = 'missing'
487-
error_message = ("Image file not found for comparison test in: \n\t"
488-
f"{self.get_baseline_directory(item)}\n"
494+
error_message = (baseline_missing +
489495
"(This is expected for new tests.)\n"
490496
"Generated Image: \n\t"
491497
f"{test_image}")

0 commit comments

Comments
 (0)