From ae729d52cf094303f979ed074acbb8c2d236f119 Mon Sep 17 00:00:00 2001 From: Ramon Giovane <40267373+RamonGiovane@users.noreply.github.com> Date: Fri, 10 Feb 2023 01:59:03 +0000 Subject: [PATCH] Option to hide local variables values in the test result output --- ward/_run.py | 7 +++++++ ward/_terminal.py | 6 +++++- ward/config.py | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/ward/_run.py b/ward/_run.py index 54bd0f97..ab3c3719 100644 --- a/ward/_run.py +++ b/ward/_run.py @@ -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", @@ -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], ): @@ -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) diff --git a/ward/_terminal.py b/ward/_terminal.py index 858206fa..37a18c90 100644 --- a/ward/_terminal.py +++ b/ward/_terminal.py @@ -676,6 +676,7 @@ 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 @@ -683,6 +684,7 @@ def __init__( 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( @@ -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)) diff --git a/ward/config.py b/ward/config.py index 9a3f5ec9..fa687407 100644 --- a/ward/config.py +++ b/ward/config.py @@ -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]