Skip to content

Commit d0b534e

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 5060c39 commit d0b534e

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
@@ -386,9 +386,8 @@ def _download_file(self, baseline, filename):
386386
self.logger.info(f'Downloading {base_url + filename} failed: {repr(e)}')
387387
else:
388388
break
389-
else:
390-
raise Exception("Could not download baseline image from any of the "
391-
"available URLs")
389+
else: # Could not download baseline image from any of the available URLs
390+
return
392391
result_dir = Path(tempfile.mkdtemp())
393392
filename = result_dir / 'downloaded'
394393
with open(str(filename), 'wb') as tmpfile:
@@ -465,17 +464,24 @@ def compare_image_to_baseline(self, item, fig, result_dir, summary=None):
465464
tolerance = compare.kwargs.get('tolerance', 2)
466465
savefig_kwargs = compare.kwargs.get('savefig_kwargs', {})
467466

468-
baseline_image_ref = self.obtain_baseline_image(item)
469-
470467
test_image = (result_dir / "result.png").absolute()
471468
fig.savefig(str(test_image), **savefig_kwargs)
472469
summary['result_image'] = test_image.relative_to(self.results_dir).as_posix()
473470

474-
if not os.path.exists(baseline_image_ref):
471+
baseline_image_ref = self.obtain_baseline_image(item)
472+
473+
baseline_missing = None
474+
if baseline_image_ref is None:
475+
baseline_missing = ("Could not download the baseline image from "
476+
"any of the available URLs.\n")
477+
elif not os.path.exists(baseline_image_ref):
478+
baseline_missing = ("Image file not found for comparison test in: \n\t"
479+
f"{self.get_baseline_directory(item)}\n")
480+
481+
if baseline_missing:
475482
summary['status'] = 'failed'
476483
summary['image_status'] = 'missing'
477-
error_message = ("Image file not found for comparison test in: \n\t"
478-
f"{self.get_baseline_directory(item)}\n"
484+
error_message = (baseline_missing +
479485
"(This is expected for new tests.)\n"
480486
"Generated Image: \n\t"
481487
f"{test_image}")

0 commit comments

Comments
 (0)