"PYLAUNCHER_LIMIT_TO_COMPANY": "",
**{k.upper(): v for k, v in (env or {}).items()},
}
+ if ini_dir := getattr(self, '_ini_dir', None):
+ env.setdefault("_PYLAUNCHER_INIDIR", ini_dir)
if not argv:
argv = [self.py_exe, *args]
with subprocess.Popen(
return data
def py_ini(self, content):
- local_appdata = os.environ.get("LOCALAPPDATA")
- if not local_appdata:
- raise unittest.SkipTest("LOCALAPPDATA environment variable is "
- "missing or empty")
- return PreservePyIni(Path(local_appdata) / "py.ini", content)
+ ini_dir = getattr(self, '_ini_dir', None)
+ if not ini_dir:
+ local_appdata = os.environ.get("LOCALAPPDATA")
+ if not local_appdata:
+ raise unittest.SkipTest("LOCALAPPDATA environment variable is "
+ "missing or empty")
+ ini_dir = local_appdata
+ return PreservePyIni(Path(ini_dir) / "py.ini", content)
@contextlib.contextmanager
def script(self, content, encoding="utf-8"):
p = subprocess.check_output("reg query HKCU\\Software\\Python /s")
#print(p.decode('mbcs'))
+ cls._ini_dir = tempfile.mkdtemp()
+ cls.addClassCleanup(shutil.rmtree, cls._ini_dir, ignore_errors=True)
@classmethod
def tearDownClass(cls):
{
wchar_t iniPath[MAXLEN];
int n;
+ // Check for _PYLAUNCHER_INIDIR override (used for test isolation)
+ DWORD len = GetEnvironmentVariableW(L"_PYLAUNCHER_INIDIR", iniPath, MAXLEN);
+ if (len && len < MAXLEN) {
+ if (join(iniPath, MAXLEN, L"py.ini")) {
+ debug(L"# Reading from %s for %s/%s\n", iniPath, section, settingName);
+ n = GetPrivateProfileStringW(section, settingName, NULL, buffer, bufferLength, iniPath);
+ if (n) {
+ debug(L"# Found %s in %s\n", settingName, iniPath);
+ return n;
+ }
+ }
+ // When _PYLAUNCHER_INIDIR is set, skip the default locations
+ return 0;
+ }
if (SUCCEEDED(SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, iniPath)) &&
join(iniPath, MAXLEN, L"py.ini")) {
debug(L"# Reading from %s for %s/%s\n", iniPath, section, settingName);