Skip to content

Commit 8484ed6

Browse files
committed
feat: record app_path in junit reports
1 parent eeb6f72 commit 8484ed6

File tree

5 files changed

+44
-13
lines changed

5 files changed

+44
-13
lines changed

pytest-embedded-idf/pytest_embedded_idf/unity_tester.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ def wrapper(self, *args, **kwargs):
288288
finally:
289289
_end_at = time.perf_counter()
290290
self._add_single_unity_test_case(
291-
_case, _log, additional_attrs={'time': round(_end_at - _start_at, 3)}
291+
_case,
292+
_log,
293+
additional_attrs={'app_path': self.app.app_path, 'time': round(_end_at - _start_at, 3)},
292294
)
293295

294296
return wrapper
@@ -695,6 +697,8 @@ def process_raw_report_data(self, raw_data_to_report) -> t.Dict:
695697
if log:
696698
attrs.update({'stdout': log})
697699

700+
attrs.update({'app_path': self.dut.app.app_path})
701+
698702
return attrs
699703

700704
def add_to_report(self, attrs):
@@ -765,9 +769,6 @@ def gather(self):
765769
for _t in self.workers:
766770
_t.close()
767771

768-
def get_processed_report_data(self, res: t.List[t.Any]) -> t.List[t.Dict]:
769-
return [self.workers[i].process_raw_report_data(res[i]) for i in range(len(res))]
770-
771772
@staticmethod
772773
def get_merge_data(test_cases_attr: t.List[t.Dict]) -> t.Dict:
773774
output = {}
@@ -794,6 +795,8 @@ def get_merge_data(test_cases_attr: t.List[t.Dict]) -> t.Dict:
794795
for k, val in output.items():
795796
if k in ('file', 'line'):
796797
output[k] = val[0]
798+
elif k == 'app_path':
799+
output[k] = '|'.join(val)
797800
else:
798801
output[k] = '<------------------->\n'.join(val)
799802

pytest-embedded-idf/tests/test_idf.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,6 +858,10 @@ def test_dut_run_all_single_board_cases(dut):
858858
assert junit_report.attrib['failures'] == '1'
859859
assert junit_report.attrib['skipped'] == '0'
860860
assert junit_report.attrib['tests'] == '1'
861+
cases = junit_report.findall('.//testcase')
862+
assert len(cases) == 2
863+
assert cases[0].attrib['app_path'] == os.path.join(testdir.tmpdir, 'unit_test_app_esp32')
864+
assert cases[1].attrib['app_path'] == os.path.join(testdir.tmpdir, 'unit_test_app_esp32')
861865

862866

863867
def test_dut_run_all_single_board_cases_invert_group(testdir):
@@ -939,14 +943,24 @@ def test_unity_test_case_runner(unity_tester):
939943
assert junit_report.attrib['skipped'] == '0'
940944
assert junit_report.attrib['tests'] == '3'
941945

946+
# single-dut app_path should be the dut[0] one
942947
assert junit_report[0].get('name') == 'normal_case1'
943948
assert junit_report[0].find('failure') is None
949+
assert junit_report[0].get('app_path') == os.path.join(testdir.tmpdir, 'unit_test_app_esp32')
944950
assert junit_report[1].get('name') == 'normal_case2'
945951
assert junit_report[1].find('failure') is not None
952+
assert junit_report[1].get('app_path') == os.path.join(testdir.tmpdir, 'unit_test_app_esp32')
946953
assert junit_report[2].get('name') == 'multiple_stages_test'
947954
assert junit_report[2].find('failure') is None
955+
assert junit_report[2].get('app_path') == os.path.join(testdir.tmpdir, 'unit_test_app_esp32')
956+
# multi-dut app_path should be concatenated
948957
assert junit_report[3].get('name') == 'multiple_devices_test'
949958
assert junit_report[3].find('failure') is None
959+
assert (
960+
junit_report[3].get('app_path') == f'{os.path.join(testdir.tmpdir, "unit_test_app_esp32")}'
961+
f'|'
962+
f'{os.path.join(testdir.tmpdir, "unit_test_app_esp32c3")}'
963+
)
950964

951965

952966
def test_erase_all_with_port_cache(testdir):

pytest-embedded/pytest_embedded/dut.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,12 @@ def expect_unity_test_output(
187187
if remove_asci_escape_code:
188188
log = remove_asci_color_code(log)
189189

190-
self.testsuite.add_unity_test_cases(log)
190+
self.testsuite.add_unity_test_cases(
191+
log,
192+
additional_attrs={
193+
'app_path': self.app.app_path,
194+
},
195+
)
191196

192197
@_InjectMixinCls.require_services('idf')
193198
def run_all_single_board_cases(

pytest-embedded/pytest_embedded/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1377,7 +1377,7 @@ def pytest_sessionfinish(self, session: Session, exitstatus: int) -> None:
13771377
_stash_session_tempdir = session.config.stash.get(_session_tempdir_key, None)
13781378
_stash_junit_report_path = session.config.stash.get(_junit_report_path_key, None)
13791379
if _stash_session_tempdir is not None:
1380-
modifier.merge(find_by_suffix('.xml', _stash_session_tempdir))
1380+
modifier.merge(sorted(find_by_suffix('.xml', _stash_session_tempdir)))
13811381

13821382
if _stash_junit_report_path:
13831383
# before we only modified the junit report generated by the unity test cases

pytest-embedded/tests/test_base.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,26 +457,33 @@ def test_expect_unity_test_output_multi_dut_with_illegal_chars(testdir):
457457
import pytest
458458
import inspect
459459
460-
output = inspect.cleandoc(
460+
output1 = inspect.cleandoc(
461461
u'''
462-
TEST(group, test_case)foo.c:100::FAIL:Expected 2 \x00 was 1
462+
TEST(group, test_case_1)foo.c:100::FAIL:Expected 2 \x00 was 1
463463
-------------------
464464
4 Tests 3 Failures 0 Ignored
465465
FAIL
466466
''')
467+
output2 = inspect.cleandoc(
468+
u'''
469+
TEST(group, test_case_2)foo.c:100::FAIL:Expected 2 \x00 was 1
470+
-------------------
471+
5 Tests 2 Failures 0 Ignored
472+
FAIL
473+
''')
467474
468475
@pytest.mark.parametrize('count', [2], indirect=True)
469476
def test_expect_unity_test_output_multi_dut_with_illegal_chars(dut):
470477
dut_0 = dut[0]
471478
dut_1 = dut[1]
472479
473-
dut_0.write(output)
474-
dut_1.write(output)
480+
dut_0.write(output1)
481+
dut_1.write(output2)
475482
dut_0.expect_unity_test_output()
476483
dut_1.expect_unity_test_output()
477484
""")
478485

479-
result = testdir.runpytest('--junitxml', 'report.xml')
486+
result = testdir.runpytest('--app-path', f'{testdir.tmpdir}/foo|{testdir.tmpdir}/bar', '--junitxml', 'report.xml')
480487

481488
try:
482489
result.assert_outcomes(failed=1)
@@ -490,10 +497,12 @@ def test_expect_unity_test_output_multi_dut_with_illegal_chars(dut):
490497
assert junit_report.attrib['skipped'] == '0'
491498
assert junit_report.attrib['tests'] == '2'
492499

493-
assert junit_report[0].get('name') == 'test_case'
500+
assert junit_report[0].get('name') == 'test_case_1'
494501
assert junit_report[0].find('failure') is not None
495-
assert junit_report[1].get('name') == 'test_case'
502+
assert junit_report[0].get('app_path') == f'{testdir.tmpdir}/foo'
503+
assert junit_report[1].get('name') == 'test_case_2'
496504
assert junit_report[1].find('failure') is not None
505+
assert junit_report[1].get('app_path') == f'{testdir.tmpdir}/bar'
497506

498507

499508
def test_duplicate_stdout_popen(testdir):

0 commit comments

Comments
 (0)