Skip to content

Commit a0e08fe

Browse files
committed
Show more information when test_installation fails
Previously, it attempted to show stderr unless empty, first falling back to stdout unless empty, then falling back to the prewritten summary identifying the specific assertion. This now has the `test_installation` assertions capture stderr as well as stdout, handle standard streams as text rather than binary, and show more information when failing, always distinguishing where the information came from: the summary, then labeled captured stdout (empty or not), then labeled captured stderr (empty or not). That applies to all but the last assertion, which does not try to show information differently when it fails, but is simplified to do the right thing now that `subprocess.run` is using text streams. (This subtly changes its semantics, but overall it should be as effective as before at finding the `sys.path` woe it anticipates.)
1 parent a2ba480 commit a0e08fe

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

test/test_installation.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,19 @@ def test_installation(self, rw_dir):
1515
venv, run = self._set_up_venv(rw_dir)
1616

1717
result = run([venv.pip, "install", "."])
18-
self.assertEqual(
19-
0,
20-
result.returncode,
21-
msg=result.stderr or result.stdout or "Can't install project",
22-
)
18+
self._check_result(result, "Can't install project")
2319

2420
result = run([venv.python, "-c", "import git"])
25-
self.assertEqual(
26-
0,
27-
result.returncode,
28-
msg=result.stderr or result.stdout or "Self-test failed",
29-
)
21+
self._check_result(result, "Self-test failed")
3022

3123
result = run([venv.python, "-c", "import gitdb; import smmap"])
32-
self.assertEqual(
33-
0,
34-
result.returncode,
35-
msg=result.stderr or result.stdout or "Dependencies not installed",
36-
)
24+
self._check_result(result, "Dependencies not installed")
3725

3826
# Even IF gitdb or any other dependency is supplied during development by
3927
# inserting its location into PYTHONPATH or otherwise patched into sys.path,
4028
# make sure it is not wrongly inserted as the *first* entry.
4129
result = run([venv.python, "-c", "import sys; import git; print(sys.path)"])
42-
syspath = result.stdout.decode("utf-8").splitlines()[0]
30+
syspath = result.stdout.splitlines()[0]
4331
syspath = ast.literal_eval(syspath)
4432
self.assertEqual(
4533
"",
@@ -63,8 +51,17 @@ def _set_up_venv(rw_dir):
6351
run = functools.partial(
6452
subprocess.run,
6553
stdout=subprocess.PIPE,
54+
stderr=subprocess.PIPE,
55+
universal_newlines=True,
6656
cwd=venv.sources,
6757
env={**os.environ, "PYTHONWARNINGS": "error"},
6858
)
6959

7060
return venv, run
61+
62+
def _check_result(self, result, failure_summary):
63+
self.assertEqual(
64+
0,
65+
result.returncode,
66+
f"{failure_summary}\nstdout:\n{result.stdout}\nstderr:\n{result.stderr}",
67+
)

0 commit comments

Comments
 (0)