test: Print REPL error message during test failures (#3124)
I noticed that the CI error messages for #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.
---------
Co-authored-by: Ignas Anikevicius <240938+aignas@users.noreply.github.com>
diff --git a/tests/repl/repl_test.py b/tests/repl/repl_test.py
index 37c9a37..01d0442 100644
--- a/tests/repl/repl_test.py
+++ b/tests/repl/repl_test.py
@@ -29,13 +29,16 @@
def run_code_in_repl(self, lines: Iterable[str], *, env=None) -> str:
"""Runs the lines of code in the REPL and returns the text output."""
- return subprocess.check_output(
- [self.repl],
- text=True,
- stderr=subprocess.STDOUT,
- input="\n".join(lines),
- env=env,
- ).strip()
+ try:
+ return subprocess.check_output(
+ [self.repl],
+ text=True,
+ stderr=subprocess.STDOUT,
+ input="\n".join(lines),
+ env=env,
+ ).strip()
+ except subprocess.CalledProcessError as error:
+ raise RuntimeError(f"Failed to run the REPL:\n{error.stdout}") from error
def test_repl_version(self):
"""Validates that we can successfully execute arbitrary code on the REPL."""