From 848ad3a70bffdf5eb2bcdee07473101a0f201996 Mon Sep 17 00:00:00 2001 From: Theofilos Manitaras Date: Tue, 27 Jul 2021 11:44:15 +0200 Subject: [PATCH 1/2] Handle `None` in `Decimal` conversion of junit report * Correctly treat `None` value for `time_total` of a `TestCase` when converting to `Decimal` during the creation of the Junit report. * Test the above in the testing of policies. --- reframe/frontend/runreport.py | 2 +- unittests/test_policies.py | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/reframe/frontend/runreport.py b/reframe/frontend/runreport.py index 5e981d2edd..a5f0d54f64 100644 --- a/reframe/frontend/runreport.py +++ b/reframe/frontend/runreport.py @@ -213,7 +213,7 @@ def junit_xml_report(json_report): # XSD schema does not like the exponential format and since # we do not want to impose a fixed width, we pass it to # `Decimal` to format it automatically. - 'time': str(decimal.Decimal(tc['time_total'])), + 'time': str(decimal.Decimal(tc['time_total'] or 0)), } ) if tc['result'] == 'failure': diff --git a/unittests/test_policies.py b/unittests/test_policies.py index 1ff0f7a546..fc41647d95 100644 --- a/unittests/test_policies.py +++ b/unittests/test_policies.py @@ -237,6 +237,9 @@ def test_runall(make_runner, make_cases, common_exec_ctx, tmp_path): with open(report_file, 'w') as fp: jsonext.dump(report, fp) + # Test handling of `None` in `time_total` in junit report + report['runs'][0]['testcases'][0]['time_total'] = None + # Validate the junit report xml_report = runreport.junit_xml_report(report) _validate_junit_report(xml_report) From b66240bde1db59169de57fb6fc63c681eae96c39 Mon Sep 17 00:00:00 2001 From: Vasileios Karakasis Date: Fri, 30 Jul 2021 00:46:49 +0200 Subject: [PATCH 2/2] Address PR comments --- unittests/test_policies.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/unittests/test_policies.py b/unittests/test_policies.py index fc41647d95..0c4a0fb8de 100644 --- a/unittests/test_policies.py +++ b/unittests/test_policies.py @@ -237,8 +237,9 @@ def test_runall(make_runner, make_cases, common_exec_ctx, tmp_path): with open(report_file, 'w') as fp: jsonext.dump(report, fp) - # Test handling of `None` in `time_total` in junit report - report['runs'][0]['testcases'][0]['time_total'] = None + # We explicitly set `time_total` to `None` in the last test case, in order + # to test the proper handling of `None`.` + report['runs'][0]['testcases'][-1]['time_total'] = None # Validate the junit report xml_report = runreport.junit_xml_report(report)