Skip to content

Commit ed3760f

Browse files
committed
TST: Mark Cairo backends as not threadsafe.
Cairo backends save the `cairo_t` object on the graphics context (as `self.gc.ctx`), but this object is not threadsafe.
1 parent ae1d2db commit ed3760f

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

lib/matplotlib/tests/test_backends_interactive.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,14 @@ def _get_testable_interactive_backends():
5050
reason = "macosx backend fails on Azure"
5151
elif 'qt5' in backend and not have_qt5:
5252
reason = "no usable Qt5 bindings"
53+
marks = []
5354
if reason:
54-
backend = pytest.param(
55-
backend,
56-
marks=pytest.mark.skip(
57-
reason=f"Skipping {backend} because {reason}"))
55+
marks.append(pytest.mark.skip(
56+
reason=f"Skipping {backend} because {reason}"))
5857
elif backend.startswith('wx') and sys.platform == 'darwin':
5958
# ignore on OSX because that's currently broken (github #16849)
60-
backend = pytest.param(
61-
backend,
62-
marks=pytest.mark.xfail(reason='github #16849'))
59+
marks.append(pytest.mark.xfail(reason='github #16849'))
60+
backend = pytest.param(backend, marks=marks)
6361
backends.append(backend)
6462
return backends
6563

@@ -216,16 +214,19 @@ def _test_thread_impl():
216214

217215
_thread_safe_backends = _get_testable_interactive_backends()
218216
# Known unsafe backends. Remove the xfails if they start to pass!
219-
if "wx" in _thread_safe_backends:
220-
_thread_safe_backends.remove("wx")
221-
_thread_safe_backends.append(
222-
pytest.param("wx", marks=pytest.mark.xfail(
223-
raises=subprocess.CalledProcessError)))
224-
if "macosx" in _thread_safe_backends:
225-
_thread_safe_backends.remove("macosx")
226-
_thread_safe_backends.append(
227-
pytest.param("macosx", marks=pytest.mark.xfail(
228-
raises=subprocess.TimeoutExpired, strict=True)))
217+
for param in _thread_safe_backends:
218+
backend = param.values[0]
219+
if "cairo" in backend:
220+
# Cairo backends save a cairo_t on the graphics context, and sharing
221+
# these is not threadsafe.
222+
param.marks.append(
223+
pytest.mark.xfail(raises=subprocess.CalledProcessError))
224+
elif backend == "wx":
225+
param.marks.append(
226+
pytest.mark.xfail(raises=subprocess.CalledProcessError))
227+
elif backend == "macosx":
228+
param.marks.append(
229+
pytest.mark.xfail(raises=subprocess.TimeoutExpired, strict=True))
229230

230231

231232
@pytest.mark.parametrize("backend", _thread_safe_backends)

0 commit comments

Comments
 (0)