Matthew Treinish | 87f772c | 2013-12-16 20:07:42 +0000 | [diff] [blame] | 1 | # 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 | |
| 15 | import os |
Jon Schlueter | 1ff7748 | 2022-01-24 17:38:48 -0500 | [diff] [blame] | 16 | import unittest |
Attila Fazekas | efe84bb | 2014-01-25 16:55:12 +0100 | [diff] [blame] | 17 | |
Matthew Treinish | 7a51877 | 2015-07-01 12:46:41 -0400 | [diff] [blame] | 18 | from tempest.test_discover import plugins |
| 19 | |
Matthew Treinish | 87f772c | 2013-12-16 20:07:42 +0000 | [diff] [blame] | 20 | |
| 21 | def load_tests(loader, tests, pattern): |
Matthew Treinish | 7a51877 | 2015-07-01 12:46:41 -0400 | [diff] [blame] | 22 | ext_plugins = plugins.TempestTestPluginManager() |
| 23 | |
Matthew Treinish | 87f772c | 2013-12-16 20:07:42 +0000 | [diff] [blame] | 24 | suite = unittest.TestSuite() |
| 25 | base_path = os.path.split(os.path.dirname(os.path.abspath(__file__)))[0] |
| 26 | base_path = os.path.split(base_path)[0] |
Matthew Treinish | 7a51877 | 2015-07-01 12:46:41 -0400 | [diff] [blame] | 27 | # Load local tempest tests |
Masayuki Igawa | 9e492ee | 2019-09-19 12:15:04 +0900 | [diff] [blame] | 28 | for test_dir in ['api', 'scenario']: |
| 29 | full_test_dir = os.path.join(base_path, 'tempest', test_dir) |
Matthew Treinish | 87f772c | 2013-12-16 20:07:42 +0000 | [diff] [blame] | 30 | if not pattern: |
Andrea Frittoli (andreaf) | d30fe3b | 2015-06-26 16:29:29 +0100 | [diff] [blame] | 31 | suite.addTests(loader.discover(full_test_dir, |
| 32 | top_level_dir=base_path)) |
Matthew Treinish | 87f772c | 2013-12-16 20:07:42 +0000 | [diff] [blame] | 33 | else: |
Andrea Frittoli (andreaf) | d30fe3b | 2015-06-26 16:29:29 +0100 | [diff] [blame] | 34 | suite.addTests(loader.discover(full_test_dir, pattern=pattern, |
afazekas | 40fcb9b | 2019-03-08 11:25:11 +0100 | [diff] [blame] | 35 | top_level_dir=base_path)) |
Matthew Treinish | 7a51877 | 2015-07-01 12:46:41 -0400 | [diff] [blame] | 36 | |
| 37 | plugin_load_tests = ext_plugins.get_plugin_load_tests_tuple() |
| 38 | if not plugin_load_tests: |
| 39 | return suite |
| 40 | |
| 41 | # Load any installed plugin tests |
| 42 | for plugin in plugin_load_tests: |
| 43 | test_dir, top_path = plugin_load_tests[plugin] |
| 44 | if not pattern: |
Marc Koderer | 704f344 | 2015-07-15 08:31:30 +0200 | [diff] [blame] | 45 | suite.addTests(loader.discover(test_dir, top_level_dir=top_path)) |
Matthew Treinish | 7a51877 | 2015-07-01 12:46:41 -0400 | [diff] [blame] | 46 | else: |
| 47 | suite.addTests(loader.discover(test_dir, pattern=pattern, |
Marc Koderer | 704f344 | 2015-07-15 08:31:30 +0200 | [diff] [blame] | 48 | top_level_dir=top_path)) |
Matthew Treinish | 87f772c | 2013-12-16 20:07:42 +0000 | [diff] [blame] | 49 | return suite |