[Python-checkins] cpython: Issue 19734: better diagnostics for test_venv failures

nick.coghlan python-checkins at python.org
Sun Nov 24 02:47:51 CET 2013


http://hg.python.org/cpython/rev/cb598129837c
changeset:   87478:cb598129837c
user:        Nick Coghlan <ncoghlan at gmail.com>
date:        Sun Nov 24 11:36:31 2013 +1000
summary:
  Issue 19734: better diagnostics for test_venv failures

files:
  Lib/test/test_venv.py |  20 ++++++++++++++++----
  Lib/venv/__init__.py  |   4 ++--
  2 files changed, 18 insertions(+), 6 deletions(-)


diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py
--- a/Lib/test/test_venv.py
+++ b/Lib/test/test_venv.py
@@ -285,15 +285,27 @@
             # warnings in current versions of Python. Ensure related
             # environment settings don't cause venv to fail.
             envvars["PYTHONWARNINGS"] = "e"
-            self.run_with_capture(venv.create, self.env_dir, with_pip=True)
+            try:
+                self.run_with_capture(venv.create, self.env_dir, with_pip=True)
+            except subprocess.CalledProcessError as exc:
+                # The output this produces can be a little hard to read, but
+                # least it has all the details
+                details = exc.output.decode(errors="replace")
+                msg = "{}\n\n**Subprocess Output**\n{}".format(exc, details)
+                self.fail(msg)
         envpy = os.path.join(os.path.realpath(self.env_dir), self.bindir, self.exe)
         cmd = [envpy, '-m', 'pip', '--version']
         p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)
         out, err = p.communicate()
-        self.assertEqual(err, b"")
-        self.assertTrue(out.startswith(b"pip"))
-        self.assertIn(self.env_dir.encode(), out)
+        # We force everything to text, so unittest gives the detailed diff
+        # if we get unexpected results
+        err = err.decode("latin-1") # Force to text, prevent decoding errors
+        self.assertEqual(err, "")
+        out = out.decode("latin-1") # Force to text, prevent decoding errors
+        env_dir = os.fsencode(self.env_dir).decode("latin-1")
+        self.assertTrue(out.startswith("pip"))
+        self.assertIn(env_dir, out)
 
 
 def test_main():
diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py
--- a/Lib/venv/__init__.py
+++ b/Lib/venv/__init__.py
@@ -237,9 +237,9 @@
         # We run ensurepip in isolated mode to avoid side effects from
         # environment vars, the current directory and anything else
         # intended for the global Python environment
-        cmd = [context.env_exe, '-Im', 'ensurepip', '--upgrade',
+        cmd = [context.env_exe, '-m', 'ensurepip', '--upgrade',
                                                     '--default-pip']
-        subprocess.check_output(cmd)
+        subprocess.check_output(cmd, stderr=subprocess.STDOUT)
 
     def setup_scripts(self, context):
         """

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list