Skip to content

Commit 6fc785a

Browse files
xtf-runner: Refactor get_all_test_info()
Signed-off-by: Bernhard Kaindl <[email protected]>
1 parent a7bdce3 commit 6fc785a

File tree

1 file changed

+7
-30
lines changed

1 file changed

+7
-30
lines changed

xtf-runner

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -237,36 +237,13 @@ _all_test_info = {} # type: Dict[str, TestInfo]
237237
def get_all_test_info():
238238
""" Open and collate each info.json """
239239

240-
# Short circuit if already cached
241-
if _all_test_info:
242-
return _all_test_info
243-
244-
for test in os.listdir("tests"):
245-
246-
info_file = None
247-
try:
248-
249-
# Ignore directories which don't have a info.json inside them
250-
try:
251-
info_file = open(path.join("tests", test, "info.json"))
252-
except IOError:
253-
continue
254-
255-
# Ignore tests which have bad JSON
256-
try:
257-
test_info = TestInfo(json.load(info_file))
258-
259-
if test_info.name != test:
260-
continue
261-
262-
except (ValueError, KeyError, TypeError):
263-
continue
264-
265-
_all_test_info[test] = test_info
266-
267-
finally:
268-
if info_file:
269-
info_file.close()
240+
if not _all_test_info:
241+
for test in os.listdir("tests"):
242+
info_file = path.join("tests", test, "info.json")
243+
if not os.path.exists(info_file):
244+
continue # Not a test dir or test was not built successfully
245+
with open(info_file) as info:
246+
_all_test_info[test] = TestInfo(json.loads(info.read()))
270247

271248
return _all_test_info
272249

0 commit comments

Comments
 (0)