File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change 15
15
import sys
16
16
import re
17
17
from textwrap import indent
18
+ from warnings import filterwarnings
18
19
19
20
from sphinx .errors import ExtensionError
20
21
from .utils import scale_image , optipng
@@ -34,6 +35,10 @@ def _import_matplotlib():
34
35
matplotlib .use ('agg' )
35
36
matplotlib_backend = matplotlib .get_backend ().lower ()
36
37
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
+
37
42
if matplotlib_backend != 'agg' :
38
43
raise ExtensionError (
39
44
"Sphinx-Gallery relies on the matplotlib 'agg' backend to "
Original file line number Diff line number Diff line change @@ -748,3 +748,15 @@ def test_minigallery_directive(sphinx_app):
748
748
# Check for examples
749
749
assert explicitorder_example .search (text ) is not None
750
750
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
You can’t perform that action at this time.
0 commit comments