@@ -179,11 +179,7 @@ def _has_tex_package(package):
179179 return False
180180
181181
182- def ipython_in_subprocess (
183- requested_backend_or_gui_framework ,
184- expected_backend_old_ipython , # IPython < 8.24
185- expected_backend_new_ipython , # IPython >= 8.24
186- ):
182+ def ipython_in_subprocess (requested_backend_or_gui_framework , all_expected_backends ):
187183 import pytest
188184 IPython = pytest .importorskip ("IPython" )
189185
@@ -194,12 +190,12 @@ def ipython_in_subprocess(
194190 requested_backend_or_gui_framework == "osx" ):
195191 pytest .skip ("Bug using macosx backend in IPython 8.24.0 fixed in 8.24.1" )
196192
197- if IPython . version_info [: 2 ] >= ( 8 , 24 ):
198- expected_backend = expected_backend_new_ipython
199- else :
200- # This code can be removed when Python 3.12, the latest version supported by
201- # IPython < 8.24, reaches end-of-life in late 2028.
202- expected_backend = expected_backend_old_ipython
193+ # This code can be removed when Python 3.12, the latest version supported
194+ # by IPython < 8.24, reaches end-of-life in late 2028.
195+ for min_version , backend in all_expected_backends . items () :
196+ if IPython . version_info [: 2 ] >= min_version :
197+ expected_backend = backend
198+ break
203199
204200 code = ("import matplotlib as mpl, matplotlib.pyplot as plt;"
205201 "fig, ax=plt.subplots(); ax.plot([1, 3, 2]); mpl.get_backend()" )
@@ -214,4 +210,4 @@ def ipython_in_subprocess(
214210 capture_output = True ,
215211 )
216212
217- assert proc .stdout .strip () == f"Out[1]: '{ expected_backend } '"
213+ assert proc .stdout .strip (). endswith ( f" '{ expected_backend } '")
0 commit comments