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

Skip to content

Commit 774f558

Browse files
committed
TST: fail gracefully if backend can not be imported
- due to missing tk libraries - due to qt already being imported
1 parent 44aa923 commit 774f558

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

lib/matplotlib/testing/conftest.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ def mpl_test_settings(request):
2626
assert len(backend_marker.args) == 1, \
2727
"Marker 'backend' must specify 1 backend."
2828
backend, = backend_marker.args
29+
skip_on_importerror = backend_marker.kwargs.get(
30+
'skip_on_importerror', False)
2931
prev_backend = matplotlib.get_backend()
3032

3133
style = '_classic_test' # Default of cleanup and image_comparison too.
@@ -45,7 +47,7 @@ def mpl_test_settings(request):
4547
except ImportError as exc:
4648
# Should only occur for the cairo backend tests, if neither
4749
# pycairo nor cairocffi are installed.
48-
if 'cairo' in backend.lower():
50+
if 'cairo' in backend.lower() or skip_on_importerror:
4951
pytest.skip("Failed to switch to backend {} ({})."
5052
.format(backend, exc))
5153
else:

lib/matplotlib/tests/test_backend_tk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from matplotlib.backends import _tkagg
55

66

7-
@pytest.mark.backend('TkAgg')
7+
@pytest.mark.backend('TkAgg', skip_on_importerror=True)
88
def test_blit():
99
def evil_blit(photoimage, aggimage, offsets, bboxptr):
1010
data = np.asarray(aggimage)

0 commit comments

Comments
 (0)