Skip to content

Commit 1469452

Browse files
committed
fix: Print REPL error message during test failures
I noticed that the CI error messages for bazel-contrib#3114 are not useful. This patch aims to help with that by printing the output of the REPL code. If there's an exception during startup for example, then the test log will now contain the stack trace.
1 parent e6bba92 commit 1469452

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

tests/repl/repl_test.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ def setUp(self):
2929

3030
def run_code_in_repl(self, lines: Iterable[str], *, env=None) -> str:
3131
"""Runs the lines of code in the REPL and returns the text output."""
32-
return subprocess.check_output(
33-
[self.repl],
34-
text=True,
35-
stderr=subprocess.STDOUT,
36-
input="\n".join(lines),
37-
env=env,
38-
).strip()
32+
try:
33+
return subprocess.check_output(
34+
[self.repl],
35+
text=True,
36+
stderr=subprocess.STDOUT,
37+
input="\n".join(lines),
38+
env=env,
39+
).strip()
40+
except subprocess.CalledProcessError as error:
41+
raise ValueError(f"Failed to run the REPL:\n{error.stdout}") from error
3942

4043
def test_repl_version(self):
4144
"""Validates that we can successfully execute arbitrary code on the REPL."""

0 commit comments

Comments
 (0)