gh-155726: Restore the sysconfig prefix cache in test_sysconfig (GH-155729)

serhiy-storchaka <[email protected]>
Newsgroups gmane.comp.python.cvs
Message-ID <[email protected]>
https://github.com/python/cpython/commit/b42025de9899003fe888a358e9e873d0411d61b3
commit: b42025de9899003fe888a358e9e873d0411d61b3
branch: main
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2026-08-14T07:39:14+03:00
summary:

gh-155726: Restore the sysconfig prefix cache in test_sysconfig (GH-155729)

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.

files:
M Lib/test/test_sysconfig.py

diff --git a/Lib/test/test_sysconfig.py b/Lib/test/test_sysconfig.py
index 9bb3e326ff3e95..b40d1a23e13df9 100644
--- a/Lib/test/test_sysconfig.py
+++ b/Lib/test/test_sysconfig.py
@@ -64,6 +64,8 @@ def setUp(self):
         self.isabs = os.path.isabs
         self.splitdrive = os.path.splitdrive
         self._config_vars = sysconfig._CONFIG_VARS, copy(sysconfig._CONFIG_VARS)
+        self._cached_prefixes = (sysconfig._config_vars_cached_prefix,
+                                 sysconfig._config_vars_cached_exec_prefix)
         self._added_envvars = []
         self._changed_envvars = []
         for var in ('MACOSX_DEPLOYMENT_TARGET', 'PATH'):
@@ -92,6 +94,11 @@ def tearDown(self):
         sysconfig._CONFIG_VARS = self._config_vars[0]
         sysconfig._CONFIG_VARS.clear()
         sysconfig._CONFIG_VARS.update(self._config_vars[1])
+        # Restoring _CONFIG_VARS is not enough: if the cached prefixes are
+        # left over from the test, the next get_config_vars() call finds
+        # the cache stale and replaces _CONFIG_VARS with a new dict.
+        (sysconfig._config_vars_cached_prefix,
+         sysconfig._config_vars_cached_exec_prefix) = self._cached_prefixes
         for var, value in self._changed_envvars:
             os.environ[var] = value
         for var in self._added_envvars:

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.