|
2 | 2 |
|
3 | 3 | from contextlib import contextmanager |
4 | 4 | import re |
| 5 | +import subprocess |
5 | 6 | from typing import ( |
6 | 7 | Sequence, |
7 | 8 | Type, |
@@ -147,17 +148,27 @@ def _assert_caught_no_extra_warnings( |
147 | 148 |
|
148 | 149 | for actual_warning in caught_warnings: |
149 | 150 | 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 |
152 | 151 | # 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 |
161 | 172 |
|
162 | 173 | extra_warnings.append( |
163 | 174 | ( |
|
0 commit comments