File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 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+ )
Original file line number Diff line number Diff line change 1414)
1515
1616from . import fixtures
17+ from .compat .py314 import warnings_helper
1718
1819
1920class 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 (),
You can’t perform that action at this time.
0 commit comments