summaryrefslogtreecommitdiffstats
path: root/Lib/test/support
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2022-10-12 15:26:21 (GMT)
committerGitHub <noreply@github.com>2022-10-12 15:26:21 (GMT)
commita8c8526fd8ce2f3f50837bbbb820741e54b58512 (patch)
tree247722821cc188088a31d3e1d76a6af2bc6e3e0f /Lib/test/support
parent0895c2a066c64c84cab0821886dfa66efc1bdc2f (diff)
downloadcpython-a8c8526fd8ce2f3f50837bbbb820741e54b58512.zip
cpython-a8c8526fd8ce2f3f50837bbbb820741e54b58512.tar.gz
cpython-a8c8526fd8ce2f3f50837bbbb820741e54b58512.tar.bz2
gh-97669: Fix test_tools reference leak (#98216)
test_tools.test_sundry() now uses an unittest mock to prevent the logging module to register a real "atfork" function which kept the logging module dictionary alive. So the logging module can be properly unloaded. Previously, the logging module was loaded before test_sundry(), but it's no longer the case since recent test_tools sub-tests removals.
Diffstat (limited to 'Lib/test/support')
-rw-r--r--Lib/test/support/import_helper.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/support/import_helper.py b/Lib/test/support/import_helper.py
index 5201dc8..63a8a79 100644
--- a/Lib/test/support/import_helper.py
+++ b/Lib/test/support/import_helper.py
@@ -246,3 +246,11 @@ def modules_cleanup(oldmodules):
# 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)