Skip to content

Commit 4357642

Browse files
authored
CI/TST: Ignore Matplotlib related ResouceWarnings from assert_produces_warning (#45073)
1 parent 4a49a25 commit 4357642

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

pandas/_testing/_warnings.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from contextlib import contextmanager
44
import re
5+
import subprocess
56
from typing import (
67
Sequence,
78
Type,
@@ -147,17 +148,27 @@ def _assert_caught_no_extra_warnings(
147148

148149
for actual_warning in caught_warnings:
149150
if _is_unexpected_warning(actual_warning, expected_warning):
150-
# GH 44732: Don't make the CI flaky by filtering SSL-related
151-
# ResourceWarning from dependencies
152151
# GH#38630 pytest.filterwarnings does not suppress these.
153-
unclosed_ssl = (
154-
"unclosed transport <asyncio.sslproto._SSLProtocolTransport",
155-
"unclosed <ssl.SSLSocket",
156-
)
157-
if actual_warning.category == ResourceWarning and any(
158-
msg in str(actual_warning.message) for msg in unclosed_ssl
159-
):
160-
continue
152+
if actual_warning.category == ResourceWarning:
153+
# GH 44732: Don't make the CI flaky by filtering SSL-related
154+
# ResourceWarning from dependencies
155+
unclosed_ssl = (
156+
"unclosed transport <asyncio.sslproto._SSLProtocolTransport",
157+
"unclosed <ssl.SSLSocket",
158+
)
159+
if any(msg in str(actual_warning.message) for msg in unclosed_ssl):
160+
continue
161+
# GH 44844: Matplotlib leaves font files open during the entire process
162+
# Don't make CI flaky if ResourceWarning raised due to these open files.
163+
try:
164+
lsof = subprocess.check_output(
165+
["lsof", "-d", "0-25", "-F", "n"]
166+
).decode("utf-8")
167+
except (subprocess.CalledProcessError, FileNotFoundError):
168+
# FileNotFoundError for Windows
169+
lsof = ""
170+
if re.search(r"\.ttf|\.ttc|\.otf", lsof):
171+
continue
161172

162173
extra_warnings.append(
163174
(

0 commit comments

Comments
 (0)