Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdd4016e

Browse files
committed
[3.10]gh-93975: Nicer error reporting in test_venv (GH-93959)
-gh-93957: Provide nicer error reporting from subprocesses in test_venv.EnsurePipTest.test_with_pip.- Update changelogThis change does three things:1. Extract a function for trapping output in subprocesses.2. Emit both stdout and stderr when encountering an error.3. Apply the change to `ensurepip._uninstall` check..(cherry picked from commit6066f45)Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
1 parentbeba102 commitdd4016e

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

‎Lib/test/test_venv.py‎

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Licensed to the PSF under a contributor agreement.
66
"""
77

8+
importcontextlib
89
importensurepip
910
importos
1011
importos.path
@@ -478,16 +479,10 @@ def do_test_with_pip(self, system_site_packages):
478479

479480
# Actually run the create command with all that unhelpful
480481
# config in place to ensure we ignore it
481-
try:
482+
withself.nicer_error():
482483
self.run_with_capture(venv.create,self.env_dir,
483484
system_site_packages=system_site_packages,
484485
with_pip=True)
485-
exceptsubprocess.CalledProcessErrorasexc:
486-
# The output this produces can be a little hard to read,
487-
# but at least it has all the details
488-
details=exc.output.decode(errors="replace")
489-
msg="{}\n\n**Subprocess Output**\n{}"
490-
self.fail(msg.format(exc,details))
491486
# Ensure pip is available in the virtual environment
492487
envpy=os.path.join(os.path.realpath(self.env_dir),self.bindir,self.exe)
493488
# Ignore DeprecationWarning since pip code is not part of Python
@@ -508,13 +503,14 @@ def do_test_with_pip(self, system_site_packages):
508503
# Check the private uninstall command provided for the Windows
509504
# installers works (at least in a virtual environment)
510505
withEnvironmentVarGuard()asenvvars:
511-
# It seems ensurepip._uninstall calls subprocesses which do not
512-
# inherit the interpreter settings.
513-
envvars["PYTHONWARNINGS"]="ignore"
514-
out,err=check_output([envpy,
515-
'-W','ignore::DeprecationWarning',
516-
'-W','ignore::ImportWarning','-I',
517-
'-m','ensurepip._uninstall'])
506+
withself.nicer_error():
507+
# It seems ensurepip._uninstall calls subprocesses which do not
508+
# inherit the interpreter settings.
509+
envvars["PYTHONWARNINGS"]="ignore"
510+
out,err=check_output([envpy,
511+
'-W','ignore::DeprecationWarning',
512+
'-W','ignore::ImportWarning','-I',
513+
'-m','ensurepip._uninstall'])
518514
# We force everything to text, so unittest gives the detailed diff
519515
# if we get unexpected results
520516
err=err.decode("latin-1")# Force to text, prevent decoding errors
@@ -540,12 +536,32 @@ def do_test_with_pip(self, system_site_packages):
540536
ifnotsystem_site_packages:
541537
self.assert_pip_not_installed()
542538

539+
@contextlib.contextmanager
540+
defnicer_error(self):
541+
"""
542+
Capture output from a failed subprocess for easier debugging.
543+
544+
The output this handler produces can be a little hard to read,
545+
but at least it has all the details.
546+
"""
547+
try:
548+
yield
549+
exceptsubprocess.CalledProcessErrorasexc:
550+
out=exc.output.decode(errors="replace")
551+
err=exc.stderr.decode(errors="replace")
552+
self.fail(
553+
f"{exc}\n\n"
554+
f"**Subprocess Output**\n{out}\n\n"
555+
f"**Subprocess Error**\n{err}"
556+
)
557+
543558
# Issue #26610: pip/pep425tags.py requires ctypes
544559
@unittest.skipUnless(ctypes,'pip requires ctypes')
545560
@requires_zlib()
546561
deftest_with_pip(self):
547562
self.do_test_with_pip(False)
548563
self.do_test_with_pip(True)
549564

565+
550566
if__name__=="__main__":
551567
unittest.main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Provide nicer error reporting from subprocesses in
2+
test_venv.EnsurePipTest.test_with_pip.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp