Skip to content

Commit faa23eb

Browse files
Fixes an issue where exception text was not being included in command output
1 parent bc80dc9 commit faa23eb

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

tripy/tests/helper.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -498,19 +498,18 @@ def process_code_block_for_outputs_and_locals(
498498
code_start, code_end = get_code_bounds(block_lines)
499499
code = dedent("\n".join(block_lines[code_start:code_end]))
500500

501-
try:
502-
with capture_output() as outfile:
501+
with capture_output() as outfile:
502+
try:
503503
code_locals = exec_code(code, local_vars)
504-
except Exception as e:
505-
if allow_exception:
506-
code_locals = local_vars
507-
else:
508-
print(
509-
f"Exception occurred while executing code block: {type(e).__name__}: {e}\n"
510-
f"Note: Code block was:\n\n{block}"
511-
)
512-
print(err_msg)
513-
raise
504+
except Exception as e:
505+
if allow_exception:
506+
# We print the error message here so it can be captured in `outfile`
507+
# and displayed in the output in cases where we actually expect exceptions.
508+
print(e)
509+
code_locals = local_vars
510+
else:
511+
print(f"{err_msg}\n" f"Note: Code block was:\n\n{block}")
512+
raise
514513

515514
new_locals = {
516515
key: value for key, value in code_locals.items() if key not in local_vars or value is not local_vars[key]

0 commit comments

Comments
 (0)