]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45128: fixes `test_multiprocessing_fork` mysterious crash (GH-28387)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 19 Sep 2021 23:13:04 +0000 (16:13 -0700)
committerGitHub <noreply@github.com>
Sun, 19 Sep 2021 23:13:04 +0000 (16:13 -0700)
(cherry picked from commit 1d42408495402b06ecae91420735aeff454be6b5)

Co-authored-by: Nikita Sobolev <mail@sobolevn.me>
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 c969a3f7665d33ec7c9e02163b795c0860d7f748..8356e6be24baf0cc05e02f4c3c112463a821c1e0 100644 (file)
@@ -4421,8 +4421,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,
@@ -4471,7 +4473,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.