From 4f164f50594817349d011dedf3de73b4ea14242f Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 13 Dec 2021 23:14:20 -0800 Subject: [PATCH 01/16] WIP: Debug ResourceWarnings BufferedRandom --- ci/run_tests.sh | 2 +- pandas/conftest.py | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/ci/run_tests.sh b/ci/run_tests.sh index 9fea696b6ea81..6a728fdece6f8 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -19,7 +19,7 @@ if [[ $(uname) == "Linux" && -z $DISPLAY ]]; then XVFB="xvfb-run " fi -PYTEST_CMD="${XVFB}pytest -m \"$PATTERN\" -n $PYTEST_WORKERS --dist=loadfile $TEST_ARGS $COVERAGE $PYTEST_TARGET" +PYTEST_CMD="${XVFB}pytest -v -m \"$PATTERN\" -n $PYTEST_WORKERS --dist=loadfile $TEST_ARGS $COVERAGE $PYTEST_TARGET" if [[ $(uname) != "Linux" && $(uname) != "Darwin" ]]; then PYTEST_CMD="$PYTEST_CMD --ignore=pandas/tests/plotting/" diff --git a/pandas/conftest.py b/pandas/conftest.py index eb9a952250f36..254e761789bdb 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -17,8 +17,6 @@ - Dtypes - Misc """ -# pyright: reportUntypedFunctionDecorator = false - from collections import abc from datetime import ( date, @@ -30,6 +28,9 @@ from decimal import Decimal import operator import os +import re +import subprocess +import sys from dateutil.tz import ( tzlocal, @@ -199,6 +200,20 @@ def add_imports(doctest_namespace): doctest_namespace["pd"] = pd +pat = re.compile(r"(0?[1-9]|1[0-9]|2[0-5])u") + + +@pytest.fixture(autouse=True) +def check_bufferedrandom_resourcewarning(): + yield + lsof = subprocess.run(["lsof"], capture_output=True).stdout.decode("utf-8") + for line in lsof.split("\n"): + if re.match(pat, line): + # sys.stderr for xdist + # https://github.com/pytest-dev/pytest/issues/1693#issuecomment-233282644 + print(line, flush=True, file=sys.stderr) + + # ---------------------------------------------------------------- # Common arguments # ---------------------------------------------------------------- From 9d23ff40deaa21d85b13e693939125b004258f21 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Tue, 14 Dec 2021 12:24:27 -0800 Subject: [PATCH 02/16] Restrict to file numbers, fix match to search --- pandas/conftest.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 254e761789bdb..cfd89746c0889 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -183,6 +183,22 @@ def pytest_collection_modifyitems(items, config): # ---------------------------------------------------------------- # Autouse fixtures # ---------------------------------------------------------------- +pat = re.compile(r"python3") + + +@pytest.fixture(autouse=True) +def check_bufferedrandom_resourcewarning(): + yield + 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(line, flush=True, file=sys.stderr) + + @pytest.fixture(autouse=True) def configure_tests(): """ @@ -200,20 +216,6 @@ def add_imports(doctest_namespace): doctest_namespace["pd"] = pd -pat = re.compile(r"(0?[1-9]|1[0-9]|2[0-5])u") - - -@pytest.fixture(autouse=True) -def check_bufferedrandom_resourcewarning(): - yield - lsof = subprocess.run(["lsof"], capture_output=True).stdout.decode("utf-8") - for line in lsof.split("\n"): - if re.match(pat, line): - # sys.stderr for xdist - # https://github.com/pytest-dev/pytest/issues/1693#issuecomment-233282644 - print(line, flush=True, file=sys.stderr) - - # ---------------------------------------------------------------- # Common arguments # ---------------------------------------------------------------- From b0cc40c5044e8d2d6e179ca73b75c806eaa27d14 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Thu, 16 Dec 2021 19:34:36 -0800 Subject: [PATCH 03/16] Mock FT2Font object that doesn't close file --- pandas/tests/plotting/conftest.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 pandas/tests/plotting/conftest.py diff --git a/pandas/tests/plotting/conftest.py b/pandas/tests/plotting/conftest.py new file mode 100644 index 0000000000000..af51d667c3e02 --- /dev/null +++ b/pandas/tests/plotting/conftest.py @@ -0,0 +1,14 @@ +import matplotlib +import pytest + + +class FT2FontCloser(matplotlib.ft2font.FT2Font): + def __init__(self, path, *args, **kwargs): + with open(path, "rb") as f: + super().__init__(f, *args, **kwargs) + + +@pytest.fixture(autouse=True) +def no_font_loading(monkeypatch): + """Remove requests.sessions.Session.request for all tests.""" + monkeypatch.setattr("matplotlib.ft2font.FT2Font", FT2FontCloser) From 580e11c5ea5b4733f74bdb238246edccf24385e2 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Thu, 16 Dec 2021 23:18:33 -0800 Subject: [PATCH 04/16] Try writing to a in memory file --- pandas/tests/plotting/conftest.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pandas/tests/plotting/conftest.py b/pandas/tests/plotting/conftest.py index af51d667c3e02..4f0c2bae9d179 100644 --- a/pandas/tests/plotting/conftest.py +++ b/pandas/tests/plotting/conftest.py @@ -1,3 +1,5 @@ +import io + import matplotlib import pytest @@ -5,7 +7,8 @@ class FT2FontCloser(matplotlib.ft2font.FT2Font): def __init__(self, path, *args, **kwargs): with open(path, "rb") as f: - super().__init__(f, *args, **kwargs) + stream = io.BytesIO(f.read()) + super().__init__(stream, *args, **kwargs) @pytest.fixture(autouse=True) From 131369a633bd7f4bdf0f4e195f3ec64c007c5819 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Fri, 17 Dec 2021 11:32:07 -0800 Subject: [PATCH 05/16] Only check in plotting tests --- pandas/conftest.py | 21 ++------------------- pandas/tests/plotting/conftest.py | 31 ++++++++++++++++++++++++------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index 15daedb133d82..8c870bc98b5ff 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -17,6 +17,8 @@ - Dtypes - Misc """ +# pyright: reportUntypedFunctionDecorator = false + from collections import abc from datetime import ( date, @@ -28,9 +30,6 @@ from decimal import Decimal import operator import os -import re -import subprocess -import sys from dateutil.tz import ( tzlocal, @@ -183,22 +182,6 @@ def pytest_collection_modifyitems(items, config): # ---------------------------------------------------------------- # Autouse fixtures # ---------------------------------------------------------------- -pat = re.compile(r"python3") - - -@pytest.fixture(autouse=True) -def check_bufferedrandom_resourcewarning(): - yield - 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(line, flush=True, file=sys.stderr) - - @pytest.fixture(autouse=True) def configure_tests(): """ diff --git a/pandas/tests/plotting/conftest.py b/pandas/tests/plotting/conftest.py index 4f0c2bae9d179..dcb306f8fabcc 100644 --- a/pandas/tests/plotting/conftest.py +++ b/pandas/tests/plotting/conftest.py @@ -1,17 +1,34 @@ import io +import re +import subprocess +import sys -import matplotlib import pytest +pat = re.compile(r"python3") -class FT2FontCloser(matplotlib.ft2font.FT2Font): - def __init__(self, path, *args, **kwargs): - with open(path, "rb") as f: - stream = io.BytesIO(f.read()) - super().__init__(stream, *args, **kwargs) + +@pytest.fixture(autouse=True) +def check_bufferedrandom_resourcewarning(request): + yield + 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 no_font_loading(monkeypatch): - """Remove requests.sessions.Session.request for all tests.""" + import matplotlib + + class FT2FontCloser(matplotlib.ft2font.FT2Font): + def __init__(self, path, *args, **kwargs): + with open(path, "rb") as f: + stream = io.BytesIO(f.read()) + super().__init__(stream, *args, **kwargs) + monkeypatch.setattr("matplotlib.ft2font.FT2Font", FT2FontCloser) From 113c108acad07db37d2fb4ab9b359e0f793c3513 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Fri, 17 Dec 2021 18:08:28 -0800 Subject: [PATCH 06/16] Try patching without importing --- pandas/tests/plotting/conftest.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/pandas/tests/plotting/conftest.py b/pandas/tests/plotting/conftest.py index dcb306f8fabcc..ed6d097b0c70c 100644 --- a/pandas/tests/plotting/conftest.py +++ b/pandas/tests/plotting/conftest.py @@ -8,6 +8,12 @@ pat = re.compile(r"python3") +def __init_closer__(self, path, *args, **kwargs): + with open(path, "rb") as f: + stream = io.BytesIO(f.read()) + super().__init__(stream, *args, **kwargs) + + @pytest.fixture(autouse=True) def check_bufferedrandom_resourcewarning(request): yield @@ -23,12 +29,12 @@ def check_bufferedrandom_resourcewarning(request): @pytest.fixture(autouse=True) def no_font_loading(monkeypatch): - import matplotlib - - class FT2FontCloser(matplotlib.ft2font.FT2Font): - def __init__(self, path, *args, **kwargs): - with open(path, "rb") as f: - stream = io.BytesIO(f.read()) - super().__init__(stream, *args, **kwargs) - - monkeypatch.setattr("matplotlib.ft2font.FT2Font", FT2FontCloser) + # import matplotlib + # + # class FT2FontCloser(matplotlib.ft2font.FT2Font): + # def __init__(self, path, *args, **kwargs): + # with open(path, "rb") as f: + # stream = io.BytesIO(f.read()) + # super().__init__(stream, *args, **kwargs) + + monkeypatch.setattr("matplotlib.ft2font.FT2Font.__init__", __init_closer__) From 83daa1bea7a6057c14a9f917c325b65b37087e7b Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Mon, 20 Dec 2021 17:49:53 -0800 Subject: [PATCH 07/16] Try clearing cache --- pandas/tests/plotting/conftest.py | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/pandas/tests/plotting/conftest.py b/pandas/tests/plotting/conftest.py index ed6d097b0c70c..59378c2beb198 100644 --- a/pandas/tests/plotting/conftest.py +++ b/pandas/tests/plotting/conftest.py @@ -1,4 +1,3 @@ -import io import re import subprocess import sys @@ -8,15 +7,13 @@ pat = re.compile(r"python3") -def __init_closer__(self, path, *args, **kwargs): - with open(path, "rb") as f: - stream = io.BytesIO(f.read()) - super().__init__(stream, *args, **kwargs) - - @pytest.fixture(autouse=True) -def check_bufferedrandom_resourcewarning(request): +def clear_font_filehandles(request): + # https://github.com/matplotlib/matplotlib/issues/22017#issuecomment-998241017 yield + import matplotlib + + matplotlib.font_manager._get_font.cache_clear() lsof = subprocess.run(["lsof", "-d", "0-25"], capture_output=True).stdout.decode( "utf-8" ) @@ -25,16 +22,3 @@ def check_bufferedrandom_resourcewarning(request): # 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 no_font_loading(monkeypatch): - # import matplotlib - # - # class FT2FontCloser(matplotlib.ft2font.FT2Font): - # def __init__(self, path, *args, **kwargs): - # with open(path, "rb") as f: - # stream = io.BytesIO(f.read()) - # super().__init__(stream, *args, **kwargs) - - monkeypatch.setattr("matplotlib.ft2font.FT2Font.__init__", __init_closer__) From 60682c868d8a3669ea78f31679ad763669d71f96 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Wed, 22 Dec 2021 15:31:45 -0800 Subject: [PATCH 08/16] Just run plotting tests to be sure --- ci/run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/run_tests.sh b/ci/run_tests.sh index 114a21a5f3f6c..8482cebe91fac 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -24,7 +24,7 @@ if [[ $(uname) == "Linux" && -z $DISPLAY ]]; then XVFB="xvfb-run " fi -PYTEST_CMD="${XVFB}pytest -v -m \"$PATTERN\" -n $PYTEST_WORKERS --dist=loadfile $TEST_ARGS $COVERAGE $PYTEST_TARGET" +PYTEST_CMD="${XVFB}pytest -v -m \"$PATTERN\" -n $PYTEST_WORKERS --dist=loadfile $TEST_ARGS $COVERAGE pandas/tests/plotting/" if [[ $(uname) != "Linux" && $(uname) != "Darwin" ]]; then PYTEST_CMD="$PYTEST_CMD --ignore=pandas/tests/plotting/" From 82efb57310a21208438f59ee657aac794d340ac4 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Thu, 23 Dec 2021 10:04:35 -0800 Subject: [PATCH 09/16] Run everything again --- ci/run_tests.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/run_tests.sh b/ci/run_tests.sh index 8482cebe91fac..114a21a5f3f6c 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -24,7 +24,7 @@ if [[ $(uname) == "Linux" && -z $DISPLAY ]]; then XVFB="xvfb-run " fi -PYTEST_CMD="${XVFB}pytest -v -m \"$PATTERN\" -n $PYTEST_WORKERS --dist=loadfile $TEST_ARGS $COVERAGE pandas/tests/plotting/" +PYTEST_CMD="${XVFB}pytest -v -m \"$PATTERN\" -n $PYTEST_WORKERS --dist=loadfile $TEST_ARGS $COVERAGE $PYTEST_TARGET" if [[ $(uname) != "Linux" && $(uname) != "Darwin" ]]; then PYTEST_CMD="$PYTEST_CMD --ignore=pandas/tests/plotting/" From 14f2f4eff19a62fae1d2d81699ef3c1c03efb44a Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Thu, 23 Dec 2021 11:00:17 -0800 Subject: [PATCH 10/16] Check if lsof printing stuff --- pandas/tests/plotting/conftest.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pandas/tests/plotting/conftest.py b/pandas/tests/plotting/conftest.py index 59378c2beb198..6196236b6cc15 100644 --- a/pandas/tests/plotting/conftest.py +++ b/pandas/tests/plotting/conftest.py @@ -17,8 +17,9 @@ def clear_font_filehandles(request): 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) + print(f"{request.node.name}\n{lsof}", flush=True, file=sys.stderr) + # 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) From 9fe484d79b0f8480b3a5e6a7a8cc92510c108fbf Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Thu, 23 Dec 2021 12:33:10 -0800 Subject: [PATCH 11/16] lsof check globally again --- pandas/conftest.py | 19 +++++++++++++++++++ pandas/tests/plotting/conftest.py | 15 --------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index be28dbe35fcb2..b543a1983f5eb 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -30,6 +30,9 @@ from decimal import Decimal import operator import os +import re +import subprocess +import sys from dateutil.tz import ( tzlocal, @@ -182,6 +185,22 @@ def pytest_collection_modifyitems(items, config): # ---------------------------------------------------------------- # Autouse fixtures # ---------------------------------------------------------------- +pat = re.compile(r"python") + + +@pytest.fixture(autouse=True) +def lsof_check(request): + yield + 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/plotting/conftest.py b/pandas/tests/plotting/conftest.py index 6196236b6cc15..a5984e62b82b3 100644 --- a/pandas/tests/plotting/conftest.py +++ b/pandas/tests/plotting/conftest.py @@ -1,11 +1,5 @@ -import re -import subprocess -import sys - import pytest -pat = re.compile(r"python3") - @pytest.fixture(autouse=True) def clear_font_filehandles(request): @@ -14,12 +8,3 @@ def clear_font_filehandles(request): import matplotlib matplotlib.font_manager._get_font.cache_clear() - lsof = subprocess.run(["lsof", "-d", "0-25"], capture_output=True).stdout.decode( - "utf-8" - ) - print(f"{request.node.name}\n{lsof}", flush=True, file=sys.stderr) - # 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) From 9ccff0d92b5c04882bd53632b30872fe87e0a5e5 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Thu, 23 Dec 2021 17:53:56 -0800 Subject: [PATCH 12/16] Clear cache in another matplotlib test --- .../tests/io/formats/style/test_matplotlib.py | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) 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): From 5bc96ae06e8d49c558a2403ad71ee5394a98c952 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Fri, 24 Dec 2021 13:09:19 -0800 Subject: [PATCH 13/16] Found another matplotlib test in pandas/tests/io/formats/test_to_excel.py --- pandas/tests/io/formats/test_to_excel.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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() From c7faf30a980a0c67a55d656e0e553e98589143ea Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Fri, 24 Dec 2021 21:22:02 -0800 Subject: [PATCH 14/16] Try clearing if matplotlib in sys modules --- pandas/conftest.py | 5 +++++ pandas/tests/plotting/conftest.py | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/pandas/conftest.py b/pandas/conftest.py index b543a1983f5eb..92bfb003e5ff5 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -191,6 +191,11 @@ def pytest_collection_modifyitems(items, config): @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" ) diff --git a/pandas/tests/plotting/conftest.py b/pandas/tests/plotting/conftest.py index a5984e62b82b3..a7b0d99b18f16 100644 --- a/pandas/tests/plotting/conftest.py +++ b/pandas/tests/plotting/conftest.py @@ -1,10 +1,10 @@ -import pytest - - -@pytest.fixture(autouse=True) -def clear_font_filehandles(request): - # https://github.com/matplotlib/matplotlib/issues/22017#issuecomment-998241017 - yield - import matplotlib - - matplotlib.font_manager._get_font.cache_clear() +# import pytest +# +# +# @pytest.fixture(autouse=True) +# def clear_font_filehandles(): +# # https://github.com/matplotlib/matplotlib/issues/22017#issuecomment-998241017 +# yield +# import matplotlib +# +# matplotlib.font_manager._get_font.cache_clear() From dcbbea227d08d2d501474902ab24b4583fcbae74 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sat, 25 Dec 2021 17:44:05 -0800 Subject: [PATCH 15/16] See what command raises on windows --- pandas/tests/api/test_types.py | 4 +++- pandas/tests/plotting/conftest.py | 10 ---------- 2 files changed, 3 insertions(+), 11 deletions(-) delete mode 100644 pandas/tests/plotting/conftest.py 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/plotting/conftest.py b/pandas/tests/plotting/conftest.py deleted file mode 100644 index a7b0d99b18f16..0000000000000 --- a/pandas/tests/plotting/conftest.py +++ /dev/null @@ -1,10 +0,0 @@ -# import pytest -# -# -# @pytest.fixture(autouse=True) -# def clear_font_filehandles(): -# # https://github.com/matplotlib/matplotlib/issues/22017#issuecomment-998241017 -# yield -# import matplotlib -# -# matplotlib.font_manager._get_font.cache_clear() From 6f6fe4a27898529e0a28be1d7d6c22d002889688 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Sat, 25 Dec 2021 20:33:44 -0800 Subject: [PATCH 16/16] Silence all lsof fixture --- ci/run_tests.sh | 2 +- pandas/conftest.py | 41 +++++++++++++++++++---------------------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/ci/run_tests.sh b/ci/run_tests.sh index 114a21a5f3f6c..203f8fe293a06 100755 --- a/ci/run_tests.sh +++ b/ci/run_tests.sh @@ -24,7 +24,7 @@ if [[ $(uname) == "Linux" && -z $DISPLAY ]]; then XVFB="xvfb-run " fi -PYTEST_CMD="${XVFB}pytest -v -m \"$PATTERN\" -n $PYTEST_WORKERS --dist=loadfile $TEST_ARGS $COVERAGE $PYTEST_TARGET" +PYTEST_CMD="${XVFB}pytest -m \"$PATTERN\" -n $PYTEST_WORKERS --dist=loadfile $TEST_ARGS $COVERAGE $PYTEST_TARGET" if [[ $(uname) != "Linux" && $(uname) != "Darwin" ]]; then PYTEST_CMD="$PYTEST_CMD --ignore=pandas/tests/plotting/" diff --git a/pandas/conftest.py b/pandas/conftest.py index 92bfb003e5ff5..76d814747411f 100644 --- a/pandas/conftest.py +++ b/pandas/conftest.py @@ -30,9 +30,6 @@ from decimal import Decimal import operator import os -import re -import subprocess -import sys from dateutil.tz import ( tzlocal, @@ -185,25 +182,25 @@ 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) +# 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)