From 8960629f3f7cc801bc97e33ca39796c849a2e304 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Mon, 19 Nov 2018 14:17:58 +0100 Subject: [PATCH 1/2] Don't fail tests if cairo dependency is not installed. --- lib/matplotlib/testing/conftest.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/testing/conftest.py b/lib/matplotlib/testing/conftest.py index d2f699c2be81..3d795f81ef62 100644 --- a/lib/matplotlib/testing/conftest.py +++ b/lib/matplotlib/testing/conftest.py @@ -43,7 +43,13 @@ def mpl_test_settings(request): # This import must come after setup() so it doesn't load the # default backend prematurely. import matplotlib.pyplot as plt - plt.switch_backend(backend) + try: + plt.switch_backend(backend) + except ImportError as exc: + # Should only occur for the cairo backend tests, if neither + # pycairo nor cairocffi are installed. + pytest.skip("Failed to switch to backend {} ({})." + .format(backend, exc)) with warnings.catch_warnings(): warnings.simplefilter("ignore", MatplotlibDeprecationWarning) matplotlib.style.use(style) From 2e1ef0d842c416113bcd94bd2db02b5fa1013245 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Tue, 20 Nov 2018 01:29:26 +0100 Subject: [PATCH 2/2] Only skip cairo import errors for testing --- lib/matplotlib/testing/conftest.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/testing/conftest.py b/lib/matplotlib/testing/conftest.py index 3d795f81ef62..8cb90e083648 100644 --- a/lib/matplotlib/testing/conftest.py +++ b/lib/matplotlib/testing/conftest.py @@ -48,8 +48,11 @@ def mpl_test_settings(request): except ImportError as exc: # Should only occur for the cairo backend tests, if neither # pycairo nor cairocffi are installed. - pytest.skip("Failed to switch to backend {} ({})." - .format(backend, exc)) + if 'cairo' in backend.lower(): + pytest.skip("Failed to switch to backend {} ({})." + .format(backend, exc)) + else: + raise with warnings.catch_warnings(): warnings.simplefilter("ignore", MatplotlibDeprecationWarning) matplotlib.style.use(style)