diff --git a/tobiko/__init__.py b/tobiko/__init__.py index 62557ca46..65b2069b0 100644 --- a/tobiko/__init__.py +++ b/tobiko/__init__.py @@ -26,5 +26,4 @@ get_fixture = fixture_manager.FIXTURES.get create_fixture = fixture_manager.FIXTURES.create delete_fixture = fixture_manager.FIXTURES.delete -discover_testcases = testcase_manager.TESTCASES.discover -load_testcase_modules = testcase_manager.TESTCASES.load_modules +discover_testcases = testcase_manager.discover_testcases diff --git a/tobiko/common/managers/testcase.py b/tobiko/common/managers/testcase.py index df41bc0a2..c03b4fcc2 100644 --- a/tobiko/common/managers/testcase.py +++ b/tobiko/common/managers/testcase.py @@ -13,7 +13,6 @@ # under the License. from __future__ import absolute_import -import importlib import os import sys @@ -25,6 +24,11 @@ LOG = log.getLogger(__name__) os.environ.setdefault('PYTHON', sys.executable) +def discover_testcases(manager=None, **kwargs): + manager = manager or TESTCASES + return manager.discover(**kwargs) + + class TestCaseManager(object): def __init__(self, config='.stestr.conf', repo_type='file', repo_url=None, @@ -69,41 +73,6 @@ class TestCaseManager(object): self.black_regex = black_regex self.filters = filters - def load_modules(self, **kwargs): - failed = {} - imported = {} - modules = [] - for testcase_id in self.discover(**kwargs): - id_parts = testcase_id.split('.') - for i in range(len(id_parts)): - module_id = '.'.join(id_parts[:i + 1]) - if module_id in failed: - # failed modules have no child modules to import - break - - # import every module only once - module = imported.get(module_id) - if module is None: - try: - module = importlib.import_module(module_id) - except ImportError as ex: - failed[module_id] = ex - self.on_import_error(module_id) - # failed modules have no child modules to import - break - assert module_id == module.__name__ - imported[module_id] = module - - if is_leaf_module(module): - # leaf modules have no child modules to import - modules.append(module) - break - - return modules - - def on_import_error(self, test_module_id): - LOG.exception("Error importing module %r", test_module_id) - def discover(self, **kwargs): """Iterate over test_ids for a project This method will print the test_ids for tests in a project. You can @@ -151,8 +120,4 @@ class TestCaseManager(object): return sorted(ids) -def is_leaf_module(module): - return not os.path.basename(module.__file__).startswith('__init__.') - - TESTCASES = TestCaseManager() diff --git a/tobiko/tests/test_testcase.py b/tobiko/tests/test_testcase.py index 54751919e..3bfc48394 100644 --- a/tobiko/tests/test_testcase.py +++ b/tobiko/tests/test_testcase.py @@ -14,7 +14,6 @@ from __future__ import absolute_import import os -import sys import tobiko from tobiko.tests import unit @@ -42,18 +41,9 @@ class TestCasesManagerTest(unit.TobikoUnitTest): os.chdir(self.top_dir) self.addCleanup(os.chdir, original_work_dir) - def test_discover(self): + def test_discover_testcases(self): testcases = tobiko.discover_testcases(test_path=self.test_path, top_dir=self.top_dir, repo_url=self.repo_url, filters=[self.id()]) self.assertIn(self.id(), testcases) - - def test_load_testcase_modules(self): - this_module = sys.modules[self.__module__] - modules = tobiko.load_testcase_modules(test_path=self.test_path, - top_dir=self.top_dir, - repo_url=self.repo_url, - filters=[self.id()]) - - self.assertIn(this_module, modules)