Skip to content

Commit

Permalink
Option to hide local variables values in the test result output
Browse files Browse the repository at this point in the history
  • Loading branch information
RamonGiovane committed Feb 10, 2023
1 parent ef53acb commit ae729d5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
7 changes: 7 additions & 0 deletions ward/_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ def run(ctx: click.Context):
help="Record and display duration of n longest running tests",
default=0,
)
@click.option(
"--show-locals/--hide-locals",
help="Print all tests without executing them",
default=True,
)
@click.option(
"--dry-run/--no-dry-run",
help="Print all tests without executing them",
Expand All @@ -174,6 +179,7 @@ def test(
capture_output: bool,
show_slowest: int,
show_diff_symbols: bool,
show_locals: bool,
dry_run: bool,
hook_module: Tuple[str],
):
Expand Down Expand Up @@ -227,6 +233,7 @@ def test(
progress_styles=progress_styles,
config_path=config_path,
show_diff_symbols=show_diff_symbols,
show_locals=show_locals,
)
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 @@ -676,13 +676,15 @@ def __init__(
progress_styles: List[TestProgressStyle],
config_path: Optional[Path],
show_diff_symbols: bool = False,
show_locals: bool = True,
):
self.console = console
self.suite = suite
self.test_output_style = test_output_style
self.progress_styles = progress_styles
self.config_path = config_path
self.show_diff_symbols = show_diff_symbols
self.show_locals = show_locals
self.terminal_size = get_terminal_size()

def output_all_test_results(
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=self.show_locals
)
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 @@ -23,6 +23,7 @@ class Config:
capture_output: bool
show_slowest: int
show_diff_symbols: bool
show_locals: bool
dry_run: bool
hook_module: Tuple[str]
progress_style: Tuple[str]
Expand Down

0 comments on commit ae729d5

Please sign in to comment.