blob: 330f370f73ea610b2327045c6ecf7e0b43f5fdfa [file] [log] [blame]
Matthew Treinish87f772c2013-12-16 20:07:42 +00001# Copyright 2013 IBM Corp.
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may
4# not use this file except in compliance with the License. You may obtain
5# a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations
13# under the License.
14
15import os
Attila Fazekasefe84bb2014-01-25 16:55:12 +010016import sys
17
Matthew Treinish7a518772015-07-01 12:46:41 -040018from tempest.test_discover import plugins
19
Attila Fazekasefe84bb2014-01-25 16:55:12 +010020if sys.version_info >= (2, 7):
21 import unittest
22else:
23 import unittest2 as unittest
Matthew Treinish87f772c2013-12-16 20:07:42 +000024
25
26def load_tests(loader, tests, pattern):
Matthew Treinish7a518772015-07-01 12:46:41 -040027 ext_plugins = plugins.TempestTestPluginManager()
28
Matthew Treinish87f772c2013-12-16 20:07:42 +000029 suite = unittest.TestSuite()
30 base_path = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0]
31 base_path = os.path.split(base_path)[0]
Matthew Treinish7a518772015-07-01 12:46:41 -040032 # Load local tempest tests
Matthew Treinish42d69512015-09-11 14:46:21 -040033 for test_dir in ['tempest/api', 'tempest/scenario']:
Andrea Frittoli (andreaf)d30fe3b2015-06-26 16:29:29 +010034 full_test_dir = os.path.join(base_path, test_dir)
Matthew Treinish87f772c2013-12-16 20:07:42 +000035 if not pattern:
Andrea Frittoli (andreaf)d30fe3b2015-06-26 16:29:29 +010036 suite.addTests(loader.discover(full_test_dir,
37 top_level_dir=base_path))
Matthew Treinish87f772c2013-12-16 20:07:42 +000038 else:
Andrea Frittoli (andreaf)d30fe3b2015-06-26 16:29:29 +010039 suite.addTests(loader.discover(full_test_dir, pattern=pattern,
Matthew Treinish87f772c2013-12-16 20:07:42 +000040 top_level_dir=base_path))
Matthew Treinish7a518772015-07-01 12:46:41 -040041
42 plugin_load_tests = ext_plugins.get_plugin_load_tests_tuple()
43 if not plugin_load_tests:
44 return suite
45
46 # Load any installed plugin tests
47 for plugin in plugin_load_tests:
48 test_dir, top_path = plugin_load_tests[plugin]
49 if not pattern:
Marc Koderer704f3442015-07-15 08:31:30 +020050 suite.addTests(loader.discover(test_dir, top_level_dir=top_path))
Matthew Treinish7a518772015-07-01 12:46:41 -040051 else:
52 suite.addTests(loader.discover(test_dir, pattern=pattern,
Marc Koderer704f3442015-07-15 08:31:30 +020053 top_level_dir=top_path))
Matthew Treinish87f772c2013-12-16 20:07:42 +000054 return suite