diff --git a/HISTORY.rst b/HISTORY.rst index baae69bf22..e42131cdb4 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -4,6 +4,7 @@ Release Notes .. |PIOCONF| replace:: `"platformio.ini" `__ configuration file .. |LDF| replace:: `LDF `__ .. |INTERPOLATION| replace:: `Interpolation of Values `__ +.. |UNITTESTING| replace:: `Unit Testing `__ .. _release_notes_6: @@ -15,7 +16,8 @@ PlatformIO Core 6 6.0.2 (2022-??-??) ~~~~~~~~~~~~~~~~~~ -* Fixed an issue when the `build_src_flags `__ were applied outside the project scope (`issue #4277 `_) +* Control |UNITTESTING| verbosity with a new `test_verbosity_level `__ configuration option (`issue #4276 `_) +* Fixed an issue when the `build_src_flags `__ option was applied outside the project scope (`issue #4277 `_) 6.0.1 (2022-05-17) ~~~~~~~~~~~~~~~~~~ @@ -58,7 +60,7 @@ Please check the `Migration guide from 5.x to 6.0 `_ solution and its documentation + - Refactored from scratch |UNITTESTING| solution and its documentation - New: `Test Hierarchy `_ (`issue #4135 `_) - New: `Doctest `__ testing framework (`issue #4240 `_) - New: `GoogleTest `__ testing and mocking framework (`issue #3572 `_) diff --git a/docs b/docs index 5bf0037c66..87c9ffa9ec 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 5bf0037c6679cccffbb835c30d729cd19120651b +Subproject commit 87c9ffa9ec156b51c7dc57e55db499991ba26100 diff --git a/platformio/project/options.py b/platformio/project/options.py index 02a8e5803f..42656c36fb 100644 --- a/platformio/project/options.py +++ b/platformio/project/options.py @@ -675,7 +675,8 @@ def get_default_core_dir(): ConfigEnvOption( group="test", name="test_speed", - description="A connection speed (baud rate) to communicate with a target device", + description="A connection speed (baud rate) to communicate with " + "a target device", type=click.INT, default=115200, ), @@ -696,6 +697,19 @@ def get_default_core_dir(): "and returns results to the standard output" ), ), + ConfigEnvOption( + group="test", + name="test_verbosity_level", + description=( + "Verbosity level: " + "0=normal verbosity (default), " + "1=raw testing output, " + "2=base verbosity for buidling/uploading, " + "3=extra verbosity for building/uploading" + ), + type=click.IntRange(min=0, max=3), + default=0, + ), # Debug ConfigEnvOption( group="debug", diff --git a/platformio/test/command.py b/platformio/test/command.py index cfc2ea3d78..f6feac2508 100644 --- a/platformio/test/command.py +++ b/platformio/test/command.py @@ -85,7 +85,12 @@ @click.option("--list-tests", is_flag=True) @click.option("--json-output-path", type=click.Path(resolve_path=True)) @click.option("--junit-output-path", type=click.Path(resolve_path=True)) -@click.option("--verbose", "-v", is_flag=True) +@click.option( + "--verbose", + "-v", + count=True, + help="Increase verbosity level, maximum is 3 levels (-vvv), see docs for details", +) @click.pass_context def test_cmd( # pylint: disable=too-many-arguments,too-many-locals,redefined-builtin ctx, @@ -121,7 +126,7 @@ def test_cmd( # pylint: disable=too-many-arguments,too-many-locals,redefined-bu test_names = sorted(set(s.test_name for s in test_suites)) if not verbose: - click.echo("Verbose mode can be enabled via `-v, --verbose` option") + click.echo("Verbosity level can be increased via `-v, --verbose` option") click.secho("Collected %d tests" % len(test_names), bold=True, nl=not verbose) if verbose: click.echo(" (%s)" % ", ".join(test_names)) @@ -134,7 +139,10 @@ def test_cmd( # pylint: disable=too-many-arguments,too-many-locals,redefined-bu test_suite, project_config, TestRunnerOptions( - verbose=verbose, + verbose=verbose + or project_config.get( + f"env:{test_suite.env_name}", "test_verbosity_level" + ), without_building=without_building, without_uploading=without_uploading, without_testing=without_testing, diff --git a/platformio/test/runners/base.py b/platformio/test/runners/base.py index ead621e572..2e49dc0876 100644 --- a/platformio/test/runners/base.py +++ b/platformio/test/runners/base.py @@ -28,7 +28,7 @@ class TestRunnerOptions: # pylint: disable=too-many-instance-attributes def __init__( # pylint: disable=too-many-arguments self, - verbose=False, + verbose=0, without_building=False, without_uploading=False, without_testing=False, @@ -96,6 +96,8 @@ def start(self, cmd_ctx): self.setup() for stage in ("building", "uploading", "testing"): getattr(self, f"stage_{stage}")() + if self.options.verbose: + click.echo() except Exception as exc: # pylint: disable=broad-except click.secho(str(exc), fg="red", err=True) self.test_suite.add_case( @@ -126,7 +128,7 @@ def stage_building(self): except ReturnErrorCode: raise UnitTestSuiteError( "Building stage has failed, see errors above. " - "Use `pio test --verbose` option to enable verbose output." + "Use `pio test -vvv` option to enable verbose output." ) def stage_uploading(self): @@ -145,7 +147,7 @@ def stage_uploading(self): except ReturnErrorCode: raise UnitTestSuiteError( "Uploading stage has failed, see errors above. " - "Use `pio test --verbose` option to enable verbose output." + "Use `pio test -vvv` option to enable verbose output." ) def stage_testing(self): @@ -179,8 +181,8 @@ def run_project_targets(self, targets): run_cmd, project_conf=self.project_config.path, upload_port=self.options.upload_port, - verbose=self.options.verbose, - silent=not self.options.verbose, + verbose=self.options.verbose > 2, + silent=self.options.verbose < 2, environment=[self.test_suite.env_name], disable_auto_clean="nobuild" in targets, target=targets, diff --git a/platformio/test/runners/doctest.py b/platformio/test/runners/doctest.py index 15f6b3116d..d0fc931fcd 100644 --- a/platformio/test/runners/doctest.py +++ b/platformio/test/runners/doctest.py @@ -119,7 +119,7 @@ def on_testing_line_output(self, line): click.echo(line, nl=False) test_case = self._tc_parser.parse(line) - if test_case: + if test_case and not self.options.verbose: click.echo(test_case.humanize()) self.test_suite.add_case(test_case) diff --git a/platformio/test/runners/googletest.py b/platformio/test/runners/googletest.py index b3687badfb..70e237e575 100644 --- a/platformio/test/runners/googletest.py +++ b/platformio/test/runners/googletest.py @@ -110,7 +110,7 @@ def on_testing_line_output(self, line): click.echo(line, nl=False) test_case = self._tc_parser.parse(line) - if test_case: + if test_case and not self.options.verbose: click.echo(test_case.humanize()) self.test_suite.add_case(test_case) diff --git a/platformio/test/runners/unity.py b/platformio/test/runners/unity.py index 6e0eae5a5d..c3604c0c14 100644 --- a/platformio/test/runners/unity.py +++ b/platformio/test/runners/unity.py @@ -264,7 +264,7 @@ def on_testing_line_output(self, line): return test_case = self.parse_test_case(line) - if test_case: + if test_case and not self.options.verbose: click.echo(test_case.humanize()) if all(s in line for s in ("Tests", "Failures", "Ignored")): diff --git a/tests/commands/test_test.py b/tests/commands/test_test.py index db7acb13fd..99fe99f4a8 100644 --- a/tests/commands/test_test.py +++ b/tests/commands/test_test.py @@ -94,6 +94,7 @@ def test_group_and_custom_runner(clirunner, validate_cliresult, tmp_path: Path): [env:native] platform = native test_framework = custom +test_verbosity_level = 1 """ ) test_dir = project_dir / "test" @@ -187,6 +188,7 @@ def teardown(self): ["-d", str(project_dir), "-e", "native", "--verbose"], ) validate_cliresult(result) + assert "1 Tests 0 Failures 0 Ignored" in result.output assert "Called from my_extra_fun" in result.output assert "CustomTestRunner::TearDown called" in result.output assert "Disabled test suite" not in result.output