Skip to content

Commit eac149f

Browse files
committed
Add tests
1 parent 14bd7fa commit eac149f

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

Lib/test/test_venv.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,23 @@ def test_devnull(self):
963963

964964
self.assertTrue(os.path.exists(os.devnull))
965965

966+
def test_ensurepip_failure_shows_stderr(self):
967+
"""Test that ensurepip failure output is shown to the user (gh-89830)"""
968+
with tempfile.TemporaryDirectory() as env_dir:
969+
builder = venv.EnvBuilder(with_pip=True)
970+
# Simulate ensurepip failing with a traceback on stderr
971+
def fake_call_new_python(context, *args, **kwargs):
972+
raise subprocess.CalledProcessError(
973+
returncode=1,
974+
cmd=args,
975+
stderr=b"AttributeError: simulated ensurepip failure"
976+
)
977+
with patch.object(venv.EnvBuilder, '_call_new_python', fake_call_new_python):
978+
with captured_stderr() as err:
979+
with self.assertRaises(subprocess.CalledProcessError):
980+
builder.create(env_dir)
981+
self.assertIn("simulated ensurepip failure", err.getvalue())
982+
966983
def do_test_with_pip(self, system_site_packages):
967984
rmtree(self.env_dir)
968985
with EnvironmentVarGuard() as envvars:

0 commit comments

Comments
 (0)