Skip to content
This repository has been archived by the owner on Oct 1, 2024. It is now read-only.

add max-frames option to limit traceback length #346

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tests/test_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def mock_rich_console():
@fixture
def writer(console=mock_rich_console):
yield TestResultWriter(
console, Suite([]), TestOutputStyle.LIVE, [TestProgressStyle.INLINE], None
console, Suite([]), TestOutputStyle.LIVE, [TestProgressStyle.INLINE], None, 100
)


Expand Down Expand Up @@ -393,6 +393,7 @@ def _(console=mock_rich_console):
test_output_style=TestOutputStyle.TEST_PER_LINE,
progress_styles=[TestProgressStyle.INLINE],
config_path=None,
max_frames=100,
)

result = result_writer.output_all_test_results(_ for _ in ())
Expand Down
8 changes: 8 additions & 0 deletions ward/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ def run(ctx: click.Context):
Pass multiple times to enable multiple styles.
""",
)
@click.option(
"--max-frames",
type=int,
default=100,
help="The maximum number of stack frames to show in tracebacks.",
)
@click.option(
"--order",
type=click.Choice(["standard", "random"], case_sensitive=False),
Expand Down Expand Up @@ -170,6 +176,7 @@ def test(
fail_limit: Optional[int],
test_output_style: str,
progress_style: List[str],
max_frames: int,
order: str,
capture_output: bool,
show_slowest: int,
Expand Down Expand Up @@ -227,6 +234,7 @@ def test(
progress_styles=progress_styles,
config_path=config_path,
show_diff_symbols=show_diff_symbols,
max_frames=max_frames,
)
for renderable in print_before:
rich_console.print(renderable)
Expand Down
6 changes: 5 additions & 1 deletion ward/_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ def __init__(
test_output_style: TestOutputStyle,
progress_styles: List[TestProgressStyle],
config_path: Optional[Path],
max_frames: int,
show_diff_symbols: bool = False,
):
self.console = console
Expand All @@ -684,6 +685,7 @@ def __init__(
self.config_path = config_path
self.show_diff_symbols = show_diff_symbols
self.terminal_size = get_terminal_size()
self.max_frames = max_frames

def output_all_test_results(
self,
Expand Down Expand Up @@ -951,7 +953,9 @@ def print_traceback(self, err):
# The first frame contains library internal code which is not
# relevant to end users, so skip over it.
trace = trace.tb_next
tb = Traceback.from_exception(err.__class__, err, trace, show_locals=True)
tb = Traceback.from_exception(
err.__class__, err, trace, show_locals=True, max_frames=self.max_frames
)
self.console.print(Padding(tb, pad=(0, 2, 1, 2)))
else:
self.console.print(str(err))
Expand Down
1 change: 1 addition & 0 deletions ward/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ class Config:
hook_module: Tuple[str]
progress_style: Tuple[str]
plugin_config: Dict[str, Dict[str, Any]]
max_frames: int