salt/tests/runtests.py
Evan Borgstrom 11cc43d22d Now that it's working let's make it a little nicer to use [GH-522]
This allows for tests to be written without too much change from the
normal unittest workflow. Now they should use the 'saltunittest'
namespace and we will need to import anything we need from the original
'unittest' or 'unittest2' namespace.
2012-01-29 10:17:51 -05:00

40 lines
1.2 KiB
Python

#!/usr/bin/env python
'''
Discover all instances of unittest.TestCase in this directory.
The current working directory must be set to the build of the salt you want to test.
'''
from saltunittest import TestLoader, TextTestRunner
from os.path import dirname, abspath, relpath, splitext, normpath
import sys, os, fnmatch
TEST_DIR = dirname(normpath(abspath(__file__)))
SALT_BUILD = os.getcwd()
TEST_FILES = '*.py'
sys.path.insert(0, TEST_DIR)
sys.path.insert(0, SALT_BUILD)
def main():
names = find_tests()
tests = TestLoader().loadTestsFromNames(names)
TextTestRunner(verbosity=1).run(tests)
def find_tests():
names = []
for root, _, files in os.walk(TEST_DIR):
for name in files:
if fnmatch.fnmatch(name, TEST_FILES) \
and not name == 'runtests.py':
module = get_test_name(root, name)
if module: names.append(module)
return names
def get_test_name(root, name):
if name.startswith("_"): return None
rel = relpath(root, TEST_DIR).lstrip(".")
prefix = "%s." % rel.replace('/','.') if rel else ""
return "".join((prefix, splitext(name)[0]))
if __name__ == "__main__":
main()