pw_unit_test: Add logs to indicate test start/end
Adds logs to test_runner.py that indicate the start/end of tests and
whether the test passed or failed.
The format is:
Test 8/365: [RUN] my_test
Test 8/365: [FAIL] my_test
...
Test 212/365: [RUN] my_other_test
Test 212/365: [PASS] my_other_test
Example:
20191126 11:44:41 AM INF Scanning for tests...
20191126 11:44:41 AM INF Found 4 test groups (10 tests).
20191126 11:44:41 AM INF Running test groups //pw_status:tests, //pw_preprocessor:tests, //pw_string:tests, //pw_span:tests
20191126 11:44:41 AM INF Test 1/10: [RUN] to_string_test
TEST - 2019-11-26 11:44:41 - INFO - Launching test binary out/stm32f429i-disc1/obj/pw_string/to_string_test.elf
TEST - 2019-11-26 11:44:41 - INFO - Flashing firmware to device...
TEST - 2019-11-26 11:44:43 - INFO - Successfully flashed firmware to device!
TEST - 2019-11-26 11:44:43 - INFO - Resetting device...
TEST - 2019-11-26 11:44:43 - INFO - Successfully reset device!
TEST - 2019-11-26 11:44:43 - INFO - Test passed!
20191126 11:44:43 AM INF Test 1/10: [PASS] to_string_test
20191126 11:44:43 AM INF Test 2/10: [RUN] status_test
TEST - 2019-11-26 11:44:43 - INFO - Launching test binary out/stm32f429i-disc1/obj/pw_status/status_test.elf
TEST - 2019-11-26 11:44:43 - INFO - Flashing firmware to device...
TEST - 2019-11-26 11:44:44 - INFO - Successfully flashed firmware to device!
TEST - 2019-11-26 11:44:44 - INFO - Resetting device...
TEST - 2019-11-26 11:44:44 - INFO - Successfully reset device!
TEST - 2019-11-26 11:44:44 - INFO - Test passed!
20191126 11:44:44 AM INF Test 2/10: [PASS] status_test
Change-Id: I916b3ea06a5a785a5d7f0f3653e96f8950037559
diff --git a/pw_unit_test/py/pw_unit_test/test_runner.py b/pw_unit_test/py/pw_unit_test/test_runner.py
index df42746..c69b235 100644
--- a/pw_unit_test/py/pw_unit_test/test_runner.py
+++ b/pw_unit_test/py/pw_unit_test/test_runner.py
@@ -121,14 +121,21 @@
def run_tests(self) -> None:
"""Runs all registered unit tests through the runner script."""
- for test in self._tests:
+ for idx, test in enumerate(self._tests, 1):
+ total = str(len(self._tests))
+ test_counter = f'Test {idx:{len(total)}}/{total}'
+
+ _LOG.info('%s: [RUN] %s', test_counter, test.name)
command = [self._executable, test.file_path, *self._args]
try:
status = subprocess.call(command)
if status == 0:
test.status = TestResult.SUCCESS
+ test_result = 'PASS'
else:
test.status = TestResult.FAILURE
+ test_result = 'FAIL'
+ _LOG.info('%s: [%s] %s', test_counter, test_result, test.name)
except subprocess.CalledProcessError as err:
_LOG.error(err)
return