aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_imp.py
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2021-09-15 10:19:30 -0600
committerGitHub <noreply@github.com>2021-09-15 10:19:30 -0600
commitcbeb81971057d6c382f45ecce92df2b204d4106a (patch)
tree98b66700b6ca5d81c863eb0b72bee6e8e38d91ca /Lib/test/test_imp.py
parent1a9ef5798525bbb39a16c8af5c435b97352ee027 (diff)
downloadcpython-cbeb81971057d6c382f45ecce92df2b204d4106a.tar.gz
cpython-cbeb81971057d6c382f45ecce92df2b204d4106a.zip
bpo-45020: Freeze some of the modules imported during startup. (gh-28335)
Doing this provides significant performance gains for runtime startup (~15% with all the imported modules frozen). We don't yet freeze all the imported modules because there are a few hiccups in the build systems we need to sort out first. (See bpo-45186 and bpo-45188.) Note that in PR GH-28320 we added a command-line flag (-X frozen_modules=[on|off]) that allows users to opt out of (or into) using frozen modules. The default is still "off" but we will change it to "on" as soon as we can do it in a way that does not cause contributors pain. https://bugs.python.org/issue45020
Diffstat (limited to 'Lib/test/test_imp.py')
-rw-r--r--Lib/test/test_imp.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/Lib/test/test_imp.py b/Lib/test/test_imp.py
index 5abe28ef62c..99312cc1625 100644
--- a/Lib/test/test_imp.py
+++ b/Lib/test/test_imp.py
@@ -16,6 +16,9 @@ with warnings.catch_warnings():
import _imp
+OS_PATH_NAME = os.path.__name__
+
+
def requires_load_dynamic(meth):
"""Decorator to skip a test if not running under CPython or lacking
imp.load_dynamic()."""
@@ -213,15 +216,17 @@ class ImportTests(unittest.TestCase):
# state after reversion. Reinitialising the module contents
# and just reverting os.environ to its previous state is an OK
# workaround
- orig_path = os.path
- orig_getenv = os.getenv
- with os_helper.EnvironmentVarGuard():
- x = imp.find_module("os")
- self.addCleanup(x[0].close)
- new_os = imp.load_module("os", *x)
- self.assertIs(os, new_os)
- self.assertIs(orig_path, new_os.path)
- self.assertIsNot(orig_getenv, new_os.getenv)
+ with import_helper.CleanImport('os', 'os.path', OS_PATH_NAME):
+ import os
+ orig_path = os.path
+ orig_getenv = os.getenv
+ with os_helper.EnvironmentVarGuard():
+ x = imp.find_module("os")
+ self.addCleanup(x[0].close)
+ new_os = imp.load_module("os", *x)
+ self.assertIs(os, new_os)
+ self.assertIs(orig_path, new_os.path)
+ self.assertIsNot(orig_getenv, new_os.getenv)
@requires_load_dynamic
def test_issue15828_load_extensions(self):