Skip to content

Commit c62ee3b

Browse files
committed
twister: remove fallback testcase if cases added at runtime
The fallback testcase, which is the scenario name from the yaml file is added if we did not discover any testcases via parsing. It can be removed if we discover testcaes at runtime or otherwise it is added as skipped... Signed-off-by: Anas Nashif <[email protected]>
1 parent bcf4e23 commit c62ee3b

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

scripts/pylib/twister/twisterlib.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,13 +1705,15 @@ def __eq__(self, other):
17051705
sorted(other.ztest_suite_names)))
17061706

17071707
class TestCase(DisablePyTestCollectionMixin):
1708+
17081709
def __init__(self, name=None, testsuite=None):
17091710
self.duration = 0
17101711
self.name = name
17111712
self.status = None
17121713
self.reason = None
17131714
self.testsuite = testsuite
17141715
self.output = ""
1716+
self.freeform = False
17151717

17161718
def __lt__(self, other):
17171719
return self.name < other.name
@@ -1781,8 +1783,9 @@ def __init__(self, testsuite_root, workdir, name):
17811783
self.ztest_suite_names = []
17821784

17831785

1784-
def add_testcase(self, name):
1786+
def add_testcase(self, name, freeform=False):
17851787
tc = TestCase(name=name, testsuite=self)
1788+
tc.freeform = freeform
17861789
self.testcases.append(tc)
17871790

17881791
@staticmethod
@@ -2058,7 +2061,7 @@ def parse_subcases(self, test_path):
20582061
self.add_testcase(name)
20592062

20602063
if not subcases:
2061-
self.add_testcase(self.id)
2064+
self.add_testcase(self.id, freeform=True)
20622065

20632066
self.ztest_suite_names = ztest_suite_names
20642067

@@ -2113,7 +2116,7 @@ def __init__(self, testsuite, platform, outdir):
21132116
# Fix an issue with copying objects from testsuite, need better solution.
21142117
def init_cases(self):
21152118
for c in self.testsuite.testcases:
2116-
self.add_testcase(c.name)
2119+
self.add_testcase(c.name, freeform=c.freeform)
21172120

21182121
def _get_run_id(self):
21192122
""" generate run id from instance unique identifier and a random
@@ -2150,8 +2153,9 @@ def set_case_status_by_name(self, name, status, reason=None):
21502153
tc.reason = reason
21512154
return tc
21522155

2153-
def add_testcase(self, name):
2156+
def add_testcase(self, name, freeform=False):
21542157
tc = TestCase(name=name)
2158+
tc.freeform = freeform
21552159
self.testcases.append(tc)
21562160
return tc
21572161

@@ -4124,7 +4128,6 @@ def json_report(self, filename, version="NA"):
41244128
if instance.status is not None:
41254129
suite["execution_time"] = f"{float(handler_time):.2f}"
41264130

4127-
41284131
testcases = []
41294132

41304133
if len(instance.testcases) == 1:
@@ -4133,6 +4136,12 @@ def json_report(self, filename, version="NA"):
41334136
single_case_duration = 0
41344137

41354138
for case in instance.testcases:
4139+
# freeform was set when no sub testcases were parsed, however,
4140+
# if we discover those at runtime, the fallback testcase wont be
4141+
# needed anymore and can be removed from the output, it does
4142+
# not have a status and would otherwise be reported as skipped.
4143+
if case.freeform and case.status is None and len(instance.testcases) > 1:
4144+
continue
41364145
testcase = {}
41374146
testcase['identifier'] = case.name
41384147
if instance.status:

0 commit comments

Comments
 (0)