From 0267a99a016bacf6f787b351eedcbb757824ef68 Mon Sep 17 00:00:00 2001 From: Antony Lee Date: Tue, 20 Nov 2018 21:58:53 +0100 Subject: [PATCH] Backport PR #12835: Don't fail tests if cairo dependency is not installed. --- lib/matplotlib/testing/conftest.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/testing/conftest.py b/lib/matplotlib/testing/conftest.py index 40ce56c4895a..96528c8de3f7 100644 --- a/lib/matplotlib/testing/conftest.py +++ b/lib/matplotlib/testing/conftest.py @@ -43,7 +43,16 @@ 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. + 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)