Skip to content

Commit d4bed64

Browse files
committed
Merge branch 'maint/8.x'
2 parents 8d6697e + 6f29e81 commit d4bed64

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

tests/compat/py314.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import contextlib
2+
import sys
3+
import types
4+
import warnings
5+
6+
from test.support import warnings_helper as orig
7+
8+
9+
@contextlib.contextmanager
10+
def ignore_warnings(*, category, message=''):
11+
"""Decorator to suppress warnings.
12+
13+
Can also be used as a context manager. This is not preferred,
14+
because it makes diffs more noisy and tools like 'git blame' less useful.
15+
But, it's useful for async functions.
16+
"""
17+
with warnings.catch_warnings():
18+
warnings.filterwarnings('ignore', category=category, message=message)
19+
yield
20+
21+
22+
@contextlib.contextmanager
23+
def ignore_fork_in_thread_deprecation_warnings():
24+
"""Suppress deprecation warnings related to forking in multi-threaded code.
25+
26+
See gh-135427
27+
28+
Can be used as decorator (preferred) or context manager.
29+
"""
30+
with ignore_warnings(
31+
message=".*fork.*may lead to deadlocks in the child.*",
32+
category=DeprecationWarning,
33+
):
34+
yield
35+
36+
37+
if sys.version_info >= (3, 15):
38+
warnings_helper = orig
39+
else:
40+
warnings_helper = types.SimpleNamespace(
41+
ignore_fork_in_thread_deprecation_warnings=ignore_fork_in_thread_deprecation_warnings,
42+
**vars(orig),
43+
)

tests/test_zip.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
)
1515

1616
from . import fixtures
17+
from .compat.py314 import warnings_helper
1718

1819

1920
class TestZip(fixtures.ZipFixtures, unittest.TestCase):
@@ -50,6 +51,7 @@ def test_one_distribution(self):
5051
dists = list(distributions(path=sys.path[:1]))
5152
assert len(dists) == 1
5253

54+
@warnings_helper.ignore_fork_in_thread_deprecation_warnings()
5355
@unittest.skipUnless(
5456
hasattr(os, 'register_at_fork')
5557
and 'fork' in multiprocessing.get_all_start_methods(),

0 commit comments

Comments
 (0)