Thanks to visit codestin.com
Credit goes to github.com

Skip to content

TST: Cache available interactive backends #27422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions lib/matplotlib/tests/test_backends_interactive.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import functools
import importlib
import importlib.util
import inspect
Expand Down Expand Up @@ -52,7 +53,10 @@ def wait_for(self, terminator):
# PyPI-installable on CI. They are not available for all tested Python
# versions so we don't fail on missing backends.

def _get_testable_interactive_backends():
@functools.lru_cache
def _get_available_interactive_backends():
_is_linux_and_display_invalid = (sys.platform == "linux" and
not _c_internal_utils.display_is_valid())
envs = []
for deps, env in [
*[([qt_api],
Expand All @@ -70,8 +74,7 @@ def _get_testable_interactive_backends():
]:
reason = None
missing = [dep for dep in deps if not importlib.util.find_spec(dep)]
if (sys.platform == "linux" and
not _c_internal_utils.display_is_valid()):
if _is_linux_and_display_invalid:
reason = "$DISPLAY and $WAYLAND_DISPLAY are unset"
elif missing:
reason = "{} cannot be imported".format(", ".join(missing))
Expand All @@ -85,8 +88,7 @@ def _get_testable_interactive_backends():
reason = "no usable GTK bindings"
marks = []
if reason:
marks.append(pytest.mark.skip(
reason=f"Skipping {env} because {reason}"))
marks.append(pytest.mark.skip(reason=f"Skipping {env} because {reason}"))
elif env["MPLBACKEND"].startswith('wx') and sys.platform == 'darwin':
# ignore on OSX because that's currently broken (github #16849)
marks.append(pytest.mark.xfail(reason='github #16849'))
Expand All @@ -97,15 +99,17 @@ def _get_testable_interactive_backends():
):
marks.append( # https://github.com/actions/setup-python/issues/649
pytest.mark.xfail(reason='Tk version mismatch on Azure macOS CI'))
envs.append(
pytest.param(
{**env, 'BACKEND_DEPS': ','.join(deps)},
marks=marks, id=str(env)
)
)
envs.append(({**env, 'BACKEND_DEPS': ','.join(deps)}, marks))
return envs


def _get_testable_interactive_backends():
# We re-create this because some of the callers below might modify the markers.
return [pytest.param({**env}, marks=[*marks],
id='-'.join(f'{k}={v}' for k, v in env.items()))
for env, marks in _get_available_interactive_backends()]


def is_ci_environment():
# Common CI variables
ci_environment_variables = [
Expand Down