From a8fc09e7d0751f30a072a7ab24351f8fc01906f9 Mon Sep 17 00:00:00 2001 From: Lukasz Langa Date: Wed, 21 Oct 2026 15:27:50 -0700 Subject: [PATCH] gh-128779: Fix system site-packages test inside a virtual environment Use the base interpreter prefixes when expanding the system install scheme so nested virtual environments are compared with the base interpreter site-packages rather than the outer virtual environment. Co-authored-by: Muse Code (Meta Muse Spark) --- Lib/test/test_site.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_site.py b/Lib/test/test_site.py index 69e5ec25ca247e..9bc7bc8b710b57 100644 --- a/Lib/test/test_site.py +++ b/Lib/test/test_site.py @@ -618,9 +618,13 @@ def test_system_site_packages(self): )) """) - # Use _get_preferred_schemes to find the system scheme, in case we are in a virtual environment + # Use the base interpreter's scheme and prefixes, even when running + # inside a virtual environment. system_scheme_name = sysconfig._get_preferred_schemes()['prefix'] - system_paths = sysconfig.get_paths(system_scheme_name) + system_paths = sysconfig.get_paths(system_scheme_name, vars={ + 'base': sys.base_prefix, + 'platbase': sys.base_exec_prefix, + }) with self.venv(system_site_packages=False) as venv: sys_path = json.loads(venv.run('-c', script).stdout)