Matthew Treinish | 519cb3e | 2013-10-28 20:27:38 +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 | |
Matthew Treinish | a0f820f | 2014-09-16 11:25:34 -0400 | [diff] [blame] | 15 | import os |
Matthew Treinish | 519cb3e | 2013-10-28 20:27:38 +0000 | [diff] [blame] | 16 | import re |
Matthew Treinish | 0948724 | 2015-05-10 12:43:58 -0400 | [diff] [blame] | 17 | import six |
Matthew Treinish | 519cb3e | 2013-10-28 20:27:38 +0000 | [diff] [blame] | 18 | import subprocess |
| 19 | |
Matthew Treinish | ffad78a | 2016-04-16 14:39:52 -0400 | [diff] [blame] | 20 | from tempest.tests import base |
Matthew Treinish | 519cb3e | 2013-10-28 20:27:38 +0000 | [diff] [blame] | 21 | |
| 22 | |
| 23 | class TestTestList(base.TestCase): |
| 24 | |
Matthew Treinish | a0f820f | 2014-09-16 11:25:34 -0400 | [diff] [blame] | 25 | def test_testr_list_tests_no_errors(self): |
| 26 | # Remove unit test discover path from env to test tempest tests |
| 27 | test_env = os.environ.copy() |
| 28 | test_env.pop('OS_TEST_PATH') |
Matthew Treinish | 519cb3e | 2013-10-28 20:27:38 +0000 | [diff] [blame] | 29 | import_failures = [] |
Matthew Treinish | a0f820f | 2014-09-16 11:25:34 -0400 | [diff] [blame] | 30 | p = subprocess.Popen(['testr', 'list-tests'], stdout=subprocess.PIPE, |
| 31 | env=test_env) |
| 32 | ids, err = p.communicate() |
| 33 | self.assertEqual(0, p.returncode, |
| 34 | "test discovery failed, one or more files cause an " |
Sean Dague | 6a9764d | 2015-01-06 17:12:16 -0500 | [diff] [blame] | 35 | "error on import %s" % ids) |
Matthew Treinish | 0948724 | 2015-05-10 12:43:58 -0400 | [diff] [blame] | 36 | ids = six.text_type(ids).split('\n') |
Matthew Treinish | 519cb3e | 2013-10-28 20:27:38 +0000 | [diff] [blame] | 37 | for test_id in ids: |
| 38 | if re.match('(\w+\.){3}\w+', test_id): |
| 39 | if not test_id.startswith('tempest.'): |
Matthew Treinish | a0f820f | 2014-09-16 11:25:34 -0400 | [diff] [blame] | 40 | parts = test_id.partition('tempest') |
| 41 | fail_id = parts[1] + parts[2] |
Matthew Treinish | 519cb3e | 2013-10-28 20:27:38 +0000 | [diff] [blame] | 42 | import_failures.append(fail_id) |
| 43 | error_message = ("The following tests have import failures and aren't" |
| 44 | " being run with test filters %s" % import_failures) |
| 45 | self.assertFalse(import_failures, error_message) |