Skip to content

Commit 213741c

Browse files
authored
Remove matplotlib agg warning (sphinx-gallery#696)
* remove warning * lint
1 parent 113bbdc commit 213741c

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

sphinx_gallery/scrapers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616
import re
1717
from textwrap import indent
18+
from warnings import filterwarnings
1819

1920
from sphinx.errors import ExtensionError
2021
from .utils import scale_image, optipng
@@ -34,6 +35,10 @@ def _import_matplotlib():
3435
matplotlib.use('agg')
3536
matplotlib_backend = matplotlib.get_backend().lower()
3637

38+
filterwarnings("ignore", category=UserWarning,
39+
message='Matplotlib is currently using agg, which is a'
40+
' non-GUI backend, so cannot show the figure.')
41+
3742
if matplotlib_backend != 'agg':
3843
raise ExtensionError(
3944
"Sphinx-Gallery relies on the matplotlib 'agg' backend to "

sphinx_gallery/tests/test_full.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,3 +748,15 @@ def test_minigallery_directive(sphinx_app):
748748
# Check for examples
749749
assert explicitorder_example.search(text) is not None
750750
assert filenamesortkey_example.search(text) is not None
751+
752+
753+
def test_matplotlib_warning_filter(sphinx_app):
754+
"""Test Matplotlib agg warning is removed."""
755+
out_dir = sphinx_app.outdir
756+
example_html = op.join(out_dir, 'auto_examples',
757+
'plot_matplotlib_alt.html')
758+
with codecs.open(example_html, 'r', 'utf-8') as fid:
759+
html = fid.read()
760+
warning = ('Matplotlib is currently using agg, which is a'
761+
' non-GUI backend, so cannot show the figure.')
762+
assert warning not in html

0 commit comments

Comments
 (0)