# do currently). Implicitly imported *real* modules should be left alone
# (see issue 10556).
sys.modules.update(oldmodules)
+
+
+def mock_register_at_fork(func):
+ # bpo-30599: Mock os.register_at_fork() when importing the random module,
+ # since this function doesn't allow to unregister callbacks and would leak
+ # memory.
+ from unittest import mock
+ return mock.patch('os.register_at_fork', create=True)(func)
import unittest
from unittest import mock
from test.support import verbose
-from test.support.import_helper import forget
+from test.support.import_helper import forget, mock_register_at_fork
from test.support.os_helper import (TESTFN, unlink, rmtree)
from test.support import script_helper, threading_helper
if finished:
done.set()
-def mock_register_at_fork(func):
- # bpo-30599: Mock os.register_at_fork() when importing the random module,
- # since this function doesn't allow to unregister callbacks and would leak
- # memory.
- return mock.patch('os.register_at_fork', create=True)(func)
-
# Create a circular import structure: A -> C -> B -> D -> A
# NOTE: `time` is already loaded and therefore doesn't threaten to deadlock.
skiplist = denylist + allowlist + other
- def test_sundry(self):
+ # import logging registers "atfork" functions which keep indirectly the
+ # logging module dictionary alive. Mock the function to be able to unload
+ # cleanly the logging module.
+ @import_helper.mock_register_at_fork
+ def test_sundry(self, mock_os):
old_modules = import_helper.modules_setup()
try:
for fn in os.listdir(scriptsdir):