summaryrefslogtreecommitdiff
path: root/Lib/test/test_venv.py
diff options
context:
space:
mode:
authorNick Coghlan <ncoghlan@gmail.com>2013-11-24 11:36:31 +1000
committerNick Coghlan <ncoghlan@gmail.com>2013-11-24 11:36:31 +1000
commit6fd12f2b33d38f64566786ff309ce84da8e9277f (patch)
treeb1d81cdf1bb90899319823cadfd5a91e759a3bdf /Lib/test/test_venv.py
parentfcafe433202300bfba33bfe16c7b48489fca59ac (diff)
downloadcpython-git-6fd12f2b33d38f64566786ff309ce84da8e9277f.tar.gz
Issue 19734: better diagnostics for test_venv failures
Diffstat (limited to 'Lib/test/test_venv.py')
-rw-r--r--Lib/test/test_venv.py20
1 files changed, 16 insertions, 4 deletions
diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py
index 87d727e8cb..613d9c3a6a 100644
--- a/Lib/test/test_venv.py
+++ b/Lib/test/test_venv.py
@@ -285,15 +285,27 @@ class EnsurePipTest(BaseTest):
# 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():