diff --git a/pandas/conftest.py b/pandas/conftest.py index be28dbe35fcb2..76d814747411f 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -182,6 +182,27 @@ def pytest_collection_modifyitems(items, config): # ---------------------------------------------------------------- # Autouse fixtures # ---------------------------------------------------------------- +# pat = re.compile(r"python") +# +# +# @pytest.fixture(autouse=True) +# def lsof_check(request): +# yield +# # https://github.com/matplotlib/matplotlib/issues/22017#issuecomment-998241017 +# if "matplotlib" in sys.modules: +# import matplotlib +# +# matplotlib.font_manager._get_font.cache_clear() +# lsof = subprocess.run(["lsof", "-d", "0-25"], capture_output=True).stdout.decode( +# "utf-8" +# ) +# for line in lsof.split("\n"): +# if re.search(pat, line): +# # sys.stderr for xdist +# # https://github.com/pytest-dev/pytest/issues/1693#issuecomment-233282644 +# print(f"{request.node.name}: {line}", flush=True, file=sys.stderr) + + @pytest.fixture(autouse=True) def configure_tests(): """ diff --git a/pandas/tests/api/test_types.py b/pandas/tests/api/test_types.py index 7b6cc9412e03d..5e5e829db9be1 100644 --- a/pandas/tests/api/test_types.py +++ b/pandas/tests/api/test_types.py @@ -1,3 +1,5 @@ +import subprocess + import pandas._testing as tm from pandas.api import types from pandas.tests.api.test_api import Base @@ -57,7 +59,7 @@ def test_types(self): self.check(types, self.allowed + self.dtypes + self.deprecated) def test_deprecated_from_api_types(self): - + subprocess.check_output(["lsof", "-d", "0-25", "-F", "n"]).decode("utf-8") for t in self.deprecated: with tm.assert_produces_warning(FutureWarning): getattr(types, t)(1) diff --git a/pandas/tests/io/formats/style/test_matplotlib.py b/pandas/tests/io/formats/style/test_matplotlib.py index a350b6fe7546d..fde9dfb189786 100644 --- a/pandas/tests/io/formats/style/test_matplotlib.py +++ b/pandas/tests/io/formats/style/test_matplotlib.py @@ -1,17 +1,16 @@ import numpy as np import pytest +import pandas.util._test_decorators as td + from pandas import ( DataFrame, IndexSlice, Series, ) -pytest.importorskip("matplotlib") pytest.importorskip("jinja2") -import matplotlib as mpl - from pandas.io.formats.style import Styler @@ -260,18 +259,23 @@ def test_background_gradient_gmap_wrong_series(styler_blank): styler_blank.background_gradient(gmap=gmap, axis=None)._compute() -@pytest.mark.parametrize("cmap", ["PuBu", mpl.cm.get_cmap("PuBu")]) -def test_bar_colormap(cmap): - data = DataFrame([[1, 2], [3, 4]]) - ctx = data.style.bar(cmap=cmap, axis=None)._compute().ctx - pubu_colors = { - (0, 0): "#d0d1e6", - (1, 0): "#056faf", - (0, 1): "#73a9cf", - (1, 1): "#023858", - } - for k, v in pubu_colors.items(): - assert v in ctx[k][1][1] +@td.skip_if_no_mpl +def test_bar_colormap(): + import matplotlib as mpl + + for cmap in ["PuBu", mpl.cm.get_cmap("PuBu")]: + data = DataFrame([[1, 2], [3, 4]]) + ctx = data.style.bar(cmap=cmap, axis=None)._compute().ctx + pubu_colors = { + (0, 0): "#d0d1e6", + (1, 0): "#056faf", + (0, 1): "#73a9cf", + (1, 1): "#023858", + } + for k, v in pubu_colors.items(): + assert v in ctx[k][1][1] + # https://github.com/matplotlib/matplotlib/issues/22017#issuecomment-998241017 + mpl.font_manager._get_font.cache_clear() def test_bar_color_raises(df): diff --git a/pandas/tests/io/formats/test_to_excel.py b/pandas/tests/io/formats/test_to_excel.py index 968ad63eaceef..da77ad82a311d 100644 --- a/pandas/tests/io/formats/test_to_excel.py +++ b/pandas/tests/io/formats/test_to_excel.py @@ -326,8 +326,12 @@ def tests_css_named_colors_valid(): @td.skip_if_no_mpl def test_css_named_colors_from_mpl_present(): - from matplotlib.colors import CSS4_COLORS as mpl_colors + import matplotlib as mpl + mpl_colors = mpl.colors.CSS4_COLORS pd_colors = CSSToExcelConverter.NAMED_COLORS for name, color in mpl_colors.items(): assert name in pd_colors and pd_colors[name] == color[1:] + + # https://github.com/matplotlib/matplotlib/issues/22017#issuecomment-998241017 + mpl.font_manager._get_font.cache_clear()