diff --git a/tests/visualize/reference/scan.png b/tests/visualize/reference/scan.png index 5c7a0747..3ac922ef 100644 Binary files a/tests/visualize/reference/scan.png and b/tests/visualize/reference/scan.png differ diff --git a/tests/visualize/test_visualize_plot_result.py b/tests/visualize/test_visualize_plot_result.py index 93b7648b..d510fa55 100644 --- a/tests/visualize/test_visualize_plot_result.py +++ b/tests/visualize/test_visualize_plot_result.py @@ -1,8 +1,10 @@ +import sys from unittest import mock import matplotlib.pyplot as plt from matplotlib.testing.compare import compare_images import numpy as np +import pytest from cabinetry.visualize import plot_result @@ -117,6 +119,10 @@ def test_ranking(tmp_path): plt.close("all") +@pytest.mark.xfail( + sys.version_info <= (3, 9), + reason="legend positioning in Python 3.8 with older matplotlib, see cabinetry#476", +) def test_scan(tmp_path): fname = tmp_path / "fig.png" par_name = "a" @@ -128,12 +134,18 @@ def test_scan(tmp_path): fig = plot_result.scan( par_name, par_mle, par_unc, par_vals, par_nlls, figure_path=fname ) - assert compare_images("tests/visualize/reference/scan.png", str(fname), 0) is None + # delay assert of comparison to be able to cover lines even with Python 3.8 + comparison_results = [] + comparison_results.append( + compare_images("tests/visualize/reference/scan.png", str(fname), 0) + ) # compare figure returned by function fname = tmp_path / "fig_from_return.png" fig.savefig(fname) - assert compare_images("tests/visualize/reference/scan.png", str(fname), 0) is None + comparison_results.append( + compare_images("tests/visualize/reference/scan.png", str(fname), 0) + ) # do not save figure, but close it with mock.patch("cabinetry.visualize.utils._save_and_close") as mock_close_safe: @@ -144,6 +156,9 @@ def test_scan(tmp_path): ) assert mock_close_safe.call_args_list == [((fig, None, True), {})] + for comp_res in comparison_results: + assert comp_res is None + plt.close("all")