diff --git a/pandas/tests/plotting/common.py b/pandas/tests/plotting/common.py index 1fb75f2c537265..9a24e4ae2dad00 100644 --- a/pandas/tests/plotting/common.py +++ b/pandas/tests/plotting/common.py @@ -19,11 +19,12 @@ import pandas.plotting as plotting from pandas.plotting._tools import _flatten - """ This is a common base class used for various plotting tests """ +tm._skip_module_if_no_mpl() + def _skip_if_no_scipy_gaussian_kde(): try: @@ -41,7 +42,6 @@ def _ok_for_gaussian_kde(kind): return True -@tm.mplskip class TestPlotBase(tm.TestCase): def setup_method(self, method): diff --git a/pandas/tests/plotting/test_boxplot_method.py b/pandas/tests/plotting/test_boxplot_method.py index 1f70d408767f37..1e06c139806576 100644 --- a/pandas/tests/plotting/test_boxplot_method.py +++ b/pandas/tests/plotting/test_boxplot_method.py @@ -21,6 +21,8 @@ """ Test cases for .boxplot method """ +tm._skip_module_if_no_mpl() + def _skip_if_mpl_14_or_dev_boxplot(): # GH 8382 @@ -31,7 +33,6 @@ def _skip_if_mpl_14_or_dev_boxplot(): pytest.skip("Matplotlib Regression in 1.4 and current dev.") -@tm.mplskip class TestDataFramePlots(TestPlotBase): @slow @@ -165,7 +166,6 @@ def test_fontsize(self): xlabelsize=16, ylabelsize=16) -@tm.mplskip class TestDataFrameGroupByPlots(TestPlotBase): @slow diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index 7908c7e9b5c72f..ed198de11bac11 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -20,8 +20,9 @@ from pandas.tests.plotting.common import (TestPlotBase, _skip_if_no_scipy_gaussian_kde) +tm._skip_module_if_no_mpl() + -@tm.mplskip class TestTSPlot(TestPlotBase): def setup_method(self, method): diff --git a/pandas/tests/plotting/test_hist_method.py b/pandas/tests/plotting/test_hist_method.py index 4792f51332571e..c3e32f52e0474e 100644 --- a/pandas/tests/plotting/test_hist_method.py +++ b/pandas/tests/plotting/test_hist_method.py @@ -15,7 +15,9 @@ from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works) -@tm.mplskip +tm._skip_module_if_no_mpl() + + class TestSeriesPlots(TestPlotBase): def setup_method(self, method): @@ -140,7 +142,6 @@ def test_plot_fails_when_ax_differs_from_figure(self): self.ts.hist(ax=ax1, figure=fig2) -@tm.mplskip class TestDataFramePlots(TestPlotBase): @slow @@ -251,7 +252,6 @@ def test_tight_layout(self): tm.close() -@tm.mplskip class TestDataFrameGroupByPlots(TestPlotBase): @slow diff --git a/pandas/tests/plotting/test_misc.py b/pandas/tests/plotting/test_misc.py index 69bf3bf6558c91..9eace32aa19a33 100644 --- a/pandas/tests/plotting/test_misc.py +++ b/pandas/tests/plotting/test_misc.py @@ -17,8 +17,9 @@ from pandas.tests.plotting.common import (TestPlotBase, _check_plot_works, _ok_for_gaussian_kde) +tm._skip_module_if_no_mpl() + -@tm.mplskip class TestSeriesPlots(TestPlotBase): def setup_method(self, method): @@ -50,7 +51,6 @@ def test_bootstrap_plot(self): _check_plot_works(bootstrap_plot, series=self.ts, size=10) -@tm.mplskip class TestDataFramePlots(TestPlotBase): @slow diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index ff27ff709f5168..448661c7af0e94 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -22,8 +22,9 @@ _skip_if_no_scipy_gaussian_kde, _ok_for_gaussian_kde) +tm._skip_module_if_no_mpl() + -@tm.mplskip class TestSeriesPlots(TestPlotBase): def setup_method(self, method): diff --git a/pandas/util/testing.py b/pandas/util/testing.py index c7d8a715d7f8b7..48eb4d32133017 100644 --- a/pandas/util/testing.py +++ b/pandas/util/testing.py @@ -283,26 +283,17 @@ def close(fignum=None): _close(fignum) -def _skip_if_32bit(): +def _skip_module_if_no_mpl(): import pytest - if is_platform_32bit(): - pytest.skip("skipping for 32 bit") + mpl = pytest.importorskip("matplotlib") + mpl.use("Agg", warn=False) -def mplskip(cls): - """Skip a TestCase instance if matplotlib isn't installed""" - @classmethod - def setup_class(cls): - try: - import matplotlib as mpl - mpl.use("Agg", warn=False) - except ImportError: - import pytest - pytest.skip("matplotlib not installed") - - cls.setup_class = setup_class - return cls +def _skip_if_32bit(): + import pytest + if is_platform_32bit(): + pytest.skip("skipping for 32 bit") def _skip_if_no_mpl():