Skip to content

Commit 83e843b

Browse files
theotherjimmyc1728p9
authored andcommitted
Fix access before variable defined bug in test_api
The worker_result variable was not guaranteed to have a `'result'` or `'reason'` key and accessing them before testing for them could result in an error when they are not provided. This patch changes the checks to prevent check for their existence before accessing them.
1 parent 65956d1 commit 83e843b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tools/test_api.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2201,12 +2201,16 @@ def build_tests(tests, base_source_paths, build_path, target, toolchain_name,
22012201
report[target_name][toolchain_name][test_key] = report_entry[test_key]
22022202

22032203
# Set the overall result to a failure if a build failure occurred
2204-
if not worker_result['result'] and not isinstance(worker_result['reason'], NotSupportedException):
2204+
if ('reason' in worker_result and
2205+
not worker_result['reason'] and
2206+
not isinstance(worker_result['reason'], NotSupportedException)):
22052207
result = False
22062208
break
22072209

22082210
# Adding binary path to test build result
2209-
if worker_result['result'] and 'bin_file' in worker_result:
2211+
if ('result' in worker_result and
2212+
worker_result['result'] and
2213+
'bin_file' in worker_result):
22102214
bin_file = norm_relative_path(worker_result['bin_file'], execution_directory)
22112215

22122216
test_build['tests'][worker_result['kwargs']['project_id']] = {

0 commit comments

Comments
 (0)