Skip to content

Commit 7ccafa4

Browse files
committed
import matplotlib lazily
Loading the relevant dependencies from matplotlib takes multiple second. There would seem to be no justification in importing matplotlib before we know whether an --mpl-* option is used, but we can even delay import until the individual tests, adding little overhead.
1 parent 7766591 commit 7ccafa4

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

pytest_mpl/plugin.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,12 @@
3939

4040
import pytest
4141

42-
import matplotlib
43-
import matplotlib.pyplot as plt
44-
from matplotlib.testing.compare import compare_images
45-
from matplotlib.testing.decorators import ImageComparisonTest as MplImageComparisonTest
46-
4742
if sys.version_info[0] == 2:
4843
from urllib import urlopen
4944
else:
5045
from urllib.request import urlopen
5146

5247

53-
MPL_LT_15 = LooseVersion(matplotlib.__version__) < LooseVersion('1.5')
54-
55-
5648
def _download_file(url):
5749
u = urlopen(url)
5850
result_dir = tempfile.mkdtemp()
@@ -115,6 +107,13 @@ def __init__(self, config, baseline_dir=None, generate_dir=None, results_dir=Non
115107

116108
def pytest_runtest_setup(self, item):
117109

110+
import matplotlib
111+
import matplotlib.pyplot as plt
112+
from matplotlib.testing.compare import compare_images
113+
from matplotlib.testing.decorators import ImageComparisonTest as MplImageComparisonTest
114+
115+
MPL_LT_15 = LooseVersion(matplotlib.__version__) < LooseVersion('1.5')
116+
118117
compare = item.keywords.get('mpl_image_compare')
119118

120119
if compare is None:

0 commit comments

Comments
 (0)