Merge pull request #172 from ChrisMacNaughton/local-tests

Allow tests to be imported from the charm directory
This commit is contained in:
Liam Young
2019-01-14 10:19:31 +00:00
committed by GitHub
2 changed files with 5 additions and 0 deletions

View File

@@ -31,6 +31,7 @@ def run_test_list(tests):
:raises: AssertionError if test run fails
"""
for _testcase in tests:
logging.info('## Running Test {} ##'.format(_testcase))
testcase = utils.get_class(_testcase)
suite = unittest.TestLoader().loadTestsFromTestCase(testcase)
test_result = unittest.TextTestRunner(verbosity=2).run(suite)

View File

@@ -15,6 +15,7 @@
"""Utilities to support running lifecycle phases."""
import importlib
import uuid
import sys
import yaml
BUNDLE_DIR = "./tests/bundles/"
@@ -46,9 +47,12 @@ def get_class(class_str):
:returns: Test class
:rtype: class
"""
old_syspath = sys.path
sys.path.append('.')
module_name = '.'.join(class_str.split('.')[:-1])
class_name = class_str.split('.')[-1]
module = importlib.import_module(module_name)
sys.path = old_syspath
return getattr(module, class_name)