Skip to content

Commit 4489fce

Browse files
committed
Fix the new test on Windows
subprocess only resolves a relative executable against its cwd argument on POSIX, so the test failed with FileNotFoundError on Windows. Change directory in the test process instead.
1 parent e022504 commit 4489fce

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

Lib/test/test_venv.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
is_wasm32,
2424
requires_venv_with_pip, TEST_HOME_DIR,
2525
requires_resource, copy_python_src_ignore)
26-
from test.support.os_helper import (can_symlink, EnvironmentVarGuard, rmtree,
27-
TESTFN, FakePath)
26+
from test.support.os_helper import (can_symlink, change_cwd, EnvironmentVarGuard,
27+
rmtree, TESTFN, FakePath)
2828
import unittest
2929
import venv
3030
from unittest.mock import patch, Mock
@@ -318,11 +318,14 @@ def test_prefixes_with_non_normalised_executable(self):
318318
self.addCleanup(rmtree, subdir)
319319
relative_exe = os.path.join(
320320
os.pardir, os.path.basename(self.env_dir), self.bindir, self.exe)
321-
p = subprocess.run(
322-
[relative_exe, '-c',
323-
'import sys; print(sys.prefix); print(sys.exec_prefix)'],
324-
cwd=subdir, capture_output=True, encoding='utf-8',
325-
env={**os.environ, 'PYTHONHOME': ''})
321+
# Windows does not resolve a relative executable against subprocess's
322+
# cwd argument, so change directory in this process instead.
323+
with change_cwd(subdir):
324+
p = subprocess.run(
325+
[relative_exe, '-c',
326+
'import sys; print(sys.prefix); print(sys.exec_prefix)'],
327+
capture_output=True, encoding='utf-8',
328+
env={**os.environ, 'PYTHONHOME': ''})
326329
self.assertEqual(p.returncode, 0, p.stderr)
327330
self.assertNotIn('Unexpected value in sys.prefix', p.stderr)
328331
self.assertNotIn('Unexpected value in sys.exec_prefix', p.stderr)

0 commit comments

Comments
 (0)