From ee6b498ca9a9ad51fc8fd1caae88871058dbc479 Mon Sep 17 00:00:00 2001 From: Ivan Kravets Date: Tue, 10 May 2022 15:25:30 +0300 Subject: [PATCH] Optimize unit testing report CLI --- HISTORY.rst | 2 +- docs | 2 +- platformio/test/command.py | 16 +++++++--------- tests/commands/test_test.py | 15 +++++---------- 4 files changed, 14 insertions(+), 21 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index d72dd852..5ed7fc2c 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -57,7 +57,7 @@ Please check `Migration guide from 5.x to 6.0 `__ (`issue #3980 `_) - Added support for the ``socket://`` and ``rfc2217://`` protocols using `test_port `__ option (`issue #4229 `_) - Pass extra arguments to the testing program with a new `pio test --program-arg `__ option (`issue #3132 `_) - - Generate reports in JUnit and JSON formats using the `pio test --output-format `__ option (`issue #2891 `_) + - Generate reports in JUnit and JSON formats using the `pio test `__ command (`issue #2891 `_) - Provide more information when the native program crashed on a host (errored with a negative return code) (`issue #3429 `_) - Fixed an issue when command line parameters (``--ignore``, ``--filter``) do not override values defined in the |PIOCONF| (`issue #3845 `_) - Renamed the "test_build_project_src" project configuration option to the `test_build_src `__ diff --git a/docs b/docs index db1960e2..41042eb9 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit db1960e263b4be666b0d35c8c53e37b66e47df3f +Subproject commit 41042eb9fddb9632a46acb30e26dc9e018426b19 diff --git a/platformio/test/command.py b/platformio/test/command.py index 91e0c69a..d0786b17 100644 --- a/platformio/test/command.py +++ b/platformio/test/command.py @@ -83,12 +83,8 @@ from platformio.test.runners.factory import TestRunnerFactory multiple=True, help="A program argument (multiple are allowed)", ) -@click.option("--output-format", type=click.Choice(["json", "junit"])) -@click.option( - "--output-path", - default=os.getcwd, - type=click.Path(dir_okay=True, resolve_path=True), -) +@click.option("--output-json", type=click.Path(resolve_path=True)) +@click.option("--output-junit", type=click.Path(resolve_path=True)) @click.option("--verbose", "-v", is_flag=True) @click.pass_context def test_cmd( # pylint: disable=too-many-arguments,too-many-locals,redefined-builtin @@ -107,8 +103,8 @@ def test_cmd( # pylint: disable=too-many-arguments,too-many-locals,redefined-bu monitor_rts, monitor_dtr, program_args, - output_format, - output_path, + output_json, + output_junit, verbose, ): app.set_session_var("custom_project_conf", project_conf) @@ -181,7 +177,9 @@ def test_cmd( # pylint: disable=too-many-arguments,too-many-locals,redefined-bu stdout_report = TestReportFactory.new("stdout", test_result) stdout_report.generate(verbose=verbose) - if output_format: + for output_format, output_path in [("json", output_json), ("junit", output_junit)]: + if not output_path: + continue custom_report = TestReportFactory.new(output_format, test_result) custom_report.generate(output_path=output_path, verbose=True) diff --git a/tests/commands/test_test.py b/tests/commands/test_test.py index 159fa427..6d59b670 100644 --- a/tests/commands/test_test.py +++ b/tests/commands/test_test.py @@ -36,8 +36,7 @@ def test_calculator_example(tmp_path: Path): "uno", "-e", "native", - "--output-format=junit", - "--output-path", + "--output-junit", str(junit_output_path), ] ) @@ -527,8 +526,7 @@ int main(int argc, char **argv) [ "-d", str(project_dir), - "--output-format=junit", - "--output-path", + "--output-junit", str(junit_output_path), ], ) @@ -553,8 +551,7 @@ int main(int argc, char **argv) [ "-d", str(project_dir), - "--output-format=json", - "--output-path", + "--output-json", str(json_output_path), "-a", "-aa=1", # fail after the 1 error @@ -578,8 +575,7 @@ def test_googletest_framework(clirunner, tmp_path: Path): project_dir, "-e", "native", - "--output-format=junit", - "--output-path", + "--output-junit", str(junit_output_path), ], ) @@ -606,8 +602,7 @@ def test_googletest_framework(clirunner, tmp_path: Path): project_dir, "-e", "native", - "--output-format=json", - "--output-path", + "--output-json", str(json_output_path), "-a", "--gtest_filter=-FooTest.Bar",