]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45128: fixes `test_multiprocessing_fork` mysterious crash (GH-28387)
authorNikita Sobolev <mail@sobolevn.me>
Sun, 19 Sep 2021 22:50:04 +0000 (01:50 +0300)
committerGitHub <noreply@github.com>
Sun, 19 Sep 2021 22:50:04 +0000 (23:50 +0100)
Lib/test/test_logging.py
Misc/NEWS.d/next/Tests/2021-09-16-17-22-35.bpo-45128.Jz6fl2.rst [new file with mode: 0644]

index 211fe4bbd7bac066a92d2c8b8d6418e32d938da3..7a80244047d0f12e2e8f7be3dabdfc16f63d8295 100644 (file)
@@ -4437,8 +4437,10 @@ class LogRecordTest(BaseTest):
             name = mp.current_process().name
 
             r1 = logging.makeLogRecord({'msg': f'msg1_{key}'})
-            del sys.modules['multiprocessing']
-            r2 = logging.makeLogRecord({'msg': f'msg2_{key}'})
+
+            # https://bugs.python.org/issue45128
+            with support.swap_item(sys.modules, 'multiprocessing', None):
+                r2 = logging.makeLogRecord({'msg': f'msg2_{key}'})
 
             results = {'processName'  : name,
                        'r1.processName': r1.processName,
@@ -4487,7 +4489,6 @@ class LogRecordTest(BaseTest):
             if multiprocessing_imported:
                 import multiprocessing
 
-
     def test_optional(self):
         r = logging.makeLogRecord({})
         NOT_NONE = self.assertIsNotNone
diff --git a/Misc/NEWS.d/next/Tests/2021-09-16-17-22-35.bpo-45128.Jz6fl2.rst b/Misc/NEWS.d/next/Tests/2021-09-16-17-22-35.bpo-45128.Jz6fl2.rst
new file mode 100644 (file)
index 0000000..b50eb32
--- /dev/null
@@ -0,0 +1,2 @@
+Fix ``test_multiprocessing_fork`` failure due to ``test_logging`` and
+``sys.modules`` manipulation.