Skip to content

Commit 75b3561

Browse files
gh-155726: Restore the sysconfig prefix cache in test_sysconfig
test_sysconfig_config_vars_no_prefix_cache changes sys.prefix and calls get_config_vars(), which caches the new prefix in module globals. tearDown() restored sysconfig._CONFIG_VARS, but not those globals, so the next get_config_vars() call found the cache stale and replaced _CONFIG_VARS with a new dict.
1 parent f056212 commit 75b3561

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

Lib/test/test_sysconfig.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ def setUp(self):
6464
self.isabs = os.path.isabs
6565
self.splitdrive = os.path.splitdrive
6666
self._config_vars = sysconfig._CONFIG_VARS, copy(sysconfig._CONFIG_VARS)
67+
self._cached_prefixes = (sysconfig._config_vars_cached_prefix,
68+
sysconfig._config_vars_cached_exec_prefix)
6769
self._added_envvars = []
6870
self._changed_envvars = []
6971
for var in ('MACOSX_DEPLOYMENT_TARGET', 'PATH'):
@@ -92,6 +94,11 @@ def tearDown(self):
9294
sysconfig._CONFIG_VARS = self._config_vars[0]
9395
sysconfig._CONFIG_VARS.clear()
9496
sysconfig._CONFIG_VARS.update(self._config_vars[1])
97+
# Restoring _CONFIG_VARS is not enough: if the cached prefixes are
98+
# left over from the test, the next get_config_vars() call finds
99+
# the cache stale and replaces _CONFIG_VARS with a new dict.
100+
(sysconfig._config_vars_cached_prefix,
101+
sysconfig._config_vars_cached_exec_prefix) = self._cached_prefixes
95102
for var, value in self._changed_envvars:
96103
os.environ[var] = value
97104
for var in self._added_envvars:

0 commit comments

Comments
 (0)