2 # Copyright (c) 2015 Cisco and/or its affiliates.
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at:
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
18 from robot.run import RobotFramework
19 from robot.conf.settings import RobotSettings
20 from robot.running.builder import TestSuiteBuilder
21 from robot.running.model import TestSuite
24 def get_suite_list(*datasources, **options):
25 class _MyRobotFramework(RobotFramework):
26 def main(self, datasources, **options):
27 # copied from robot.run.RobotFramework.main
28 settings = RobotSettings(options)
29 suite = TestSuiteBuilder(settings['SuiteNames'],
30 settings['WarnOnSkipped']).build(*datasources)
31 suite.configure(**settings.suite_config)
35 # Options are in robot.conf.settings
36 suite = _MyRobotFramework().execute(*datasources, **options)
37 if isinstance(suite, TestSuite):
45 if len(s.suites._items) > 0:
46 for i in s.suites._items:
54 # TODO: add from robot.errors typ error
58 def run_suites(test_dir, suites, out_dir="./outputs", **options):
62 for f in os.listdir(out_dir):
63 os.remove('/'.join((out_dir, f)))
66 if not os.path.exists(out_dir):
72 varfile.append('resources/libraries/python/topology.py')
74 # TODO: check testcases Tags
76 with open('{}/{}.out'.format(out_dir, longname), 'w') as out, \
77 open('{}/{}.log'.format(out_dir, longname), 'w') as debug:
80 output='{}/{}.xml'.format(out_dir, longname),
89 def parse_outputs(out_dir='./'):
90 outs = ['/'.join((out_dir, file)) for file in os.listdir(out_dir) if file.endswith('.xml')]
91 robot.rebot(*outs, merge=True)
94 if __name__ == "__main__":
101 out_dir = "./outputs"
103 suite_list = get_suite_list(test_dir, include=i, exclude=e, output=None, dryrun=True)
104 run_suites(test_dir, suite_list, include=i, exclude=e, out_dir=out_dir)
105 parse_outputs(out_dir=out_dir)