From 99377130ebebfa788b25d7fda0baf15aee6426c8 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Mon, 27 May 2019 22:25:48 +0300 Subject: [PATCH] Enhance unit testing summary --- platformio/commands/run.py | 5 +++-- platformio/commands/test/command.py | 20 ++++++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/platformio/commands/run.py b/platformio/commands/run.py index b75c8962..41fca7e0 100644 --- a/platformio/commands/run.py +++ b/platformio/commands/run.py @@ -314,11 +314,12 @@ def _clean_build_dir(build_dir): f.write(proj_hash) -def print_header(label, is_error=False): +def print_header(label, is_error=False, fg=None): terminal_width, _ = click.get_terminal_size() width = len(click.unstyle(label)) half_line = "=" * int((terminal_width - width - 2) / 2) - click.echo("%s %s %s" % (half_line, label, half_line), err=is_error) + click.secho( + "%s %s %s" % (half_line, label, half_line), fg=fg, err=is_error) def print_summary(results, start_time): diff --git a/platformio/commands/test/command.py b/platformio/commands/test/command.py index bd98d3f4..5f41649b 100644 --- a/platformio/commands/test/command.py +++ b/platformio/commands/test/command.py @@ -148,7 +148,8 @@ def cli( # pylint: disable=redefined-builtin if without_testing: return - passed = True + passed_nums = 0 + failed_nums = 0 testname_max_len = max([len(r[1]) for r in results]) envname_max_len = max([len(click.style(r[2], fg="cyan")) for r in results]) @@ -157,12 +158,14 @@ def cli( # pylint: disable=redefined-builtin for result in results: status, testname, envname = result - status_str = click.style("PASSED", fg="green") if status is False: - passed = False + failed_nums += 1 status_str = click.style("FAILED", fg="red") elif status is None: status_str = click.style("IGNORED", fg="yellow") + else: + passed_nums += 1 + status_str = click.style("PASSED", fg="green") click.echo( ("test/{:<%d} > {:<%d}\t[{}]" % @@ -171,12 +174,13 @@ def cli( # pylint: disable=redefined-builtin err=status is False) print_header( - "[%s] Took %.2f seconds" % ( - (click.style("PASSED", fg="green", bold=True) if passed else - click.style("FAILED", fg="red", bold=True)), time() - start_time), - is_error=not passed) + "%s%d passed in %.2f seconds" + % ("%d failed, " % failed_nums if failed_nums else "", passed_nums, + time() - start_time), + is_error=failed_nums, + fg="red" if failed_nums else "green") - if not passed: + if failed_nums: raise exception.ReturnErrorCode(1)