1+ import functools
12import importlib
23import importlib .util
34import inspect
@@ -52,7 +53,10 @@ def wait_for(self, terminator):
5253# PyPI-installable on CI. They are not available for all tested Python
5354# versions so we don't fail on missing backends.
5455
55- def _get_testable_interactive_backends ():
56+ @functools .lru_cache
57+ def _get_available_interactive_backends ():
58+ _is_linux_and_display_invalid = (sys .platform == "linux" and
59+ not _c_internal_utils .display_is_valid ())
5660 envs = []
5761 for deps , env in [
5862 * [([qt_api ],
@@ -70,8 +74,7 @@ def _get_testable_interactive_backends():
7074 ]:
7175 reason = None
7276 missing = [dep for dep in deps if not importlib .util .find_spec (dep )]
73- if (sys .platform == "linux" and
74- not _c_internal_utils .display_is_valid ()):
77+ if _is_linux_and_display_invalid :
7578 reason = "$DISPLAY and $WAYLAND_DISPLAY are unset"
7679 elif missing :
7780 reason = "{} cannot be imported" .format (", " .join (missing ))
@@ -85,8 +88,7 @@ def _get_testable_interactive_backends():
8588 reason = "no usable GTK bindings"
8689 marks = []
8790 if reason :
88- marks .append (pytest .mark .skip (
89- reason = f"Skipping { env } because { reason } " ))
91+ marks .append (pytest .mark .skip (reason = f"Skipping { env } because { reason } " ))
9092 elif env ["MPLBACKEND" ].startswith ('wx' ) and sys .platform == 'darwin' :
9193 # ignore on OSX because that's currently broken (github #16849)
9294 marks .append (pytest .mark .xfail (reason = 'github #16849' ))
@@ -97,15 +99,17 @@ def _get_testable_interactive_backends():
9799 ):
98100 marks .append ( # https://github.com/actions/setup-python/issues/649
99101 pytest .mark .xfail (reason = 'Tk version mismatch on Azure macOS CI' ))
100- envs .append (
101- pytest .param (
102- {** env , 'BACKEND_DEPS' : ',' .join (deps )},
103- marks = marks , id = str (env )
104- )
105- )
102+ envs .append (({** env , 'BACKEND_DEPS' : ',' .join (deps )}, marks ))
106103 return envs
107104
108105
106+ def _get_testable_interactive_backends ():
107+ # We re-create this because some of the callers below might modify the markers.
108+ return [pytest .param ({** env }, marks = [* marks ],
109+ id = '-' .join (f'{ k } ={ v } ' for k , v in env .items ()))
110+ for env , marks in _get_available_interactive_backends ()]
111+
112+
109113def is_ci_environment ():
110114 # Common CI variables
111115 ci_environment_variables = [
0 commit comments