Skip to content

Commit 9b39d39

Browse files
committed
[Util] Fix in unittest-parallel.py script.
Exit with exit code 1 on failure of a test.
1 parent 0f41d3b commit 9b39d39

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

utils/unittest-parallel.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ def dump(self, out: str):
5454
else:
5555
result_xml.write(sys.stdout.buffer)
5656

57+
def is_failure(self):
58+
if (self.errors > 0 or self.failures > 0):
59+
return True
60+
else:
61+
return False
62+
63+
5764
# data needed for human readable output
5865
class TestData:
5966
total_assertions = 0
@@ -138,6 +145,11 @@ def dump(self, _):
138145
print(f'\u001b[32;1mAll tests passed\u001b[39;0m ({self.passed_assertions} assertions in {self.passed_test_cases} test cases)\n')
139146
print(f'Execution time: {self.execution_time}s\n')
140147

148+
def is_failure(self):
149+
if (self.failed_assertions > 0 or self.failed_test_cases > 0):
150+
return True
151+
else:
152+
return False
141153

142154

143155
def run_tests(args, test_names: list[str], binary_path: str, is_interactive: bool):
@@ -217,8 +229,7 @@ def run_tests(args, test_names: list[str], binary_path: str, is_interactive: boo
217229
execution_time = time_end - time_start
218230
data.execution_time = execution_time
219231

220-
out = args.out
221-
data.dump(out)
232+
return data
222233

223234

224235
if __name__ == '__main__':
@@ -251,5 +262,11 @@ def run_tests(args, test_names: list[str], binary_path: str, is_interactive: boo
251262
output = subprocess.run(list_tests_command, shell=True, stdout=subprocess.PIPE)
252263
test_names = output.stdout.decode().strip().split('\n')
253264

254-
run_tests(args, test_names, args.binary_path, is_interactive)
265+
data = run_tests(args, test_names, args.binary_path, is_interactive)
266+
267+
data.dump(args.out)
268+
if data.is_failure():
269+
exit(1)
270+
else:
271+
exit(0)
255272

0 commit comments

Comments
 (0)