From 9880696398eeea56797a73515c77553b93b8dbc4 Mon Sep 17 00:00:00 2001 From: Matthew Roeschke Date: Thu, 6 Jan 2022 11:43:18 -0800 Subject: [PATCH] Backport PR #45204: CI: Use broader condition to maybe catch ResourceWarning from Matplotlib --- pandas/_testing/_warnings.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/pandas/_testing/_warnings.py b/pandas/_testing/_warnings.py index 44a62e607555e..f9443f80e585c 100644 --- a/pandas/_testing/_warnings.py +++ b/pandas/_testing/_warnings.py @@ -2,7 +2,7 @@ from contextlib import contextmanager import re -import subprocess +import sys from typing import ( Sequence, Type, @@ -159,15 +159,9 @@ def _assert_caught_no_extra_warnings( if any(msg in str(actual_warning.message) for msg in unclosed_ssl): continue # GH 44844: Matplotlib leaves font files open during the entire process - # Don't make CI flaky if ResourceWarning raised due to these open files. - try: - lsof = subprocess.check_output( - ["lsof", "-d", "0-25", "-F", "n"] - ).decode("utf-8") - except (subprocess.CalledProcessError, FileNotFoundError): - # FileNotFoundError for Windows - lsof = "" - if re.search(r"\.ttf|\.ttc|\.otf", lsof): + # upon import. Don't make CI flaky if ResourceWarning raised + # due to these open files. + if any("matplotlib" in mod for mod in sys.modules): continue extra_warnings.append(