-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_in_parallel.py
47 lines (35 loc) · 1.3 KB
/
run_in_parallel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import argparse
import json
from multiprocessing import Pool
from subprocess import call, Popen, PIPE
def parse_arguments():
"""Parse the runtime arguments"""
parser = argparse.ArgumentParser()
parser.add_argument('--suite', '-s', default='tests/features')
parser.add_argument('--processes', '-p', type=int, default=5)
parser.add_argument('--tags', '-t')
return parser.parse_args()
def _run_parallel_feature(feature):
"""Runs the features passed to it"""
cmd = 'behave -f allure -o reports {feature}'.format(feature=feature)
r = call(cmd, shell=True)
status = 'Passed' if r == 0 else 'Failed'
print('{0:50}: {1}!!'.format(feature, status))
return feature, status
def main():
"""Run Behave in parallel"""
args = parse_arguments()
pool = Pool(args.processes)
cmd = 'behave {suite}/. -t {tags} -d -f json --no-summary'.format(
suite=args.suite, tags=args.tags)
p = Popen(cmd, stdout=PIPE, shell=True)
out, err = p.communicate()
if err is not None:
print(err)
features = [scenario['location'] for scenario in json.loads(out.decode())]
with open("features","w") as file:
for feature in features:
file.write("%s\n" % feature)
pool.map(_run_parallel_feature, features)
if __name__ == '__main__':
main()