Skip to content

Fix headless tests on Wayland. #19083

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 16, 2020
Merged
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions lib/matplotlib/tests/test_backends_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pytest

import matplotlib as mpl
from matplotlib import _c_internal_utils


# Minimal smoke-testing of the backends for which the dependencies are
Expand Down Expand Up @@ -40,8 +41,9 @@ 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 os.environ.get("DISPLAY"):
reason = "$DISPLAY is unset"
if (sys.platform == "linux" and
not _c_internal_utils.display_is_valid()):
reason = "$DISPLAY and $WAYLAND_DISPLAY are unset"
elif missing:
reason = "{} cannot be imported".format(", ".join(missing))
elif backend == 'macosx' and os.environ.get('TF_BUILD'):
Expand Down Expand Up @@ -276,7 +278,8 @@ def test_lazy_linux_headless():
import sys

# make it look headless
del os.environ['DISPLAY']
os.environ.pop('DISPLAY', None)
os.environ.pop('WAYLAND_DISPLAY', None)

# we should fast-track to Agg
import matplotlib.pyplot as plt
Expand Down
10 changes: 6 additions & 4 deletions lib/matplotlib/tests/test_rcparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import pytest

import matplotlib as mpl
from matplotlib import _api
from matplotlib import _api, _c_internal_utils
import matplotlib.pyplot as plt
import matplotlib.colors as mcolors
import numpy as np
Expand Down Expand Up @@ -476,7 +476,8 @@ def test_rcparams_reset_after_fail():
@pytest.mark.skipif(sys.platform != "linux", reason="Linux only")
def test_backend_fallback_headless(tmpdir):
env = {**os.environ,
"DISPLAY": "", "MPLBACKEND": "", "MPLCONFIGDIR": str(tmpdir)}
"DISPLAY": "", "WAYLAND_DISPLAY": "",
"MPLBACKEND": "", "MPLCONFIGDIR": str(tmpdir)}
with pytest.raises(subprocess.CalledProcessError):
subprocess.run(
[sys.executable, "-c",
Expand All @@ -487,8 +488,9 @@ def test_backend_fallback_headless(tmpdir):
env=env, check=True)


@pytest.mark.skipif(sys.platform == "linux" and not os.environ.get("DISPLAY"),
reason="headless")
@pytest.mark.skipif(
sys.platform == "linux" and not _c_internal_utils.display_is_valid(),
reason="headless")
def test_backend_fallback_headful(tmpdir):
pytest.importorskip("tkinter")
env = {**os.environ, "MPLBACKEND": "", "MPLCONFIGDIR": str(tmpdir)}
Expand Down