Merge pull request #172 from ChrisMacNaughton/local-tests
Allow tests to be imported from the charm directory
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user