示例#1
0
def callback(item):

    print "Catch the modification of '{0}'".format(item.path)
    test_path = os.path.join(os.path.dirname(__file__), '../tests')
    test_loader = loader.TestLoader()
    testrunner = TextTestRunner(verbosity=2)
    testrunner.run(test_loader.discover(test_path))
    print "=" * 80
示例#2
0
def scan_tests(modules):
    overall_suite = load_tests(modules, loader.TestLoader())

    max_required_mds = 0
    max_required_clients = 0

    for suite, case in enumerate_methods(overall_suite):
        max_required_mds = max(max_required_mds,
                               getattr(case, "MDSS_REQUIRED", 0))
        max_required_clients = max(max_required_clients,
                               getattr(case, "CLIENTS_REQUIRED", 0))

    return max_required_mds, max_required_clients
示例#3
0
def scan_tests(modules):
    overall_suite = load_tests(modules, loader.TestLoader())

    max_required_mds = 0
    max_required_clients = 0
    max_required_mgr = 0
    require_memstore = False

    for suite, case in enumerate_methods(overall_suite):
        max_required_mds = max(max_required_mds,
                               getattr(case, "MDSS_REQUIRED", 0))
        max_required_clients = max(max_required_clients,
                                   getattr(case, "CLIENTS_REQUIRED", 0))
        max_required_mgr = max(max_required_mgr,
                               getattr(case, "MGRS_REQUIRED", 0))
        require_memstore = getattr(case, "REQUIRE_MEMSTORE", False) \
                               or require_memstore

    return max_required_mds, max_required_clients, \
            max_required_mgr, require_memstore
示例#4
0
def discover_stress_tests(path="./", filter_attr=None, call_inherited=False):
    """Discovers all tempest tests and create action out of them
    """
    LOG.info("Start test discovery")
    tests = []
    testloader = loader.TestLoader()
    list = testloader.discover(path)
    for func in (testsuite.iterate_tests(list)):
        attrs = []
        try:
            method_name = getattr(func, '_testMethodName')
            full_name = "%s.%s.%s" % (func.__module__, func.__class__.__name__,
                                      method_name)
            test_func = getattr(func, method_name)
            # NOTE(mkoderer): this contains a list of all type attributes
            attrs = getattr(test_func, "__testtools_attrs")
        except Exception:
            next
        if 'stress' in attrs:
            if filter_attr is not None and filter_attr not in attrs:
                continue
            class_setup_per = getattr(test_func, "st_class_setup_per")

            action = {
                'action': "tempest.stress.actions.unit_test.UnitTest",
                'kwargs': {
                    "test_method": full_name,
                    "class_setup_per": class_setup_per
                }
            }
            if (not call_inherited and getattr(
                    test_func, "st_allow_inheritance") is not True):
                class_structure = inspect.getmro(test_func.im_class)
                if test_func.__name__ not in class_structure[0].__dict__:
                    continue
            tests.append(action)
    return tests
示例#5
0
文件: test.py 项目: qmssof/py-gfm
The unittest in python 2.6 doesn't have the loader function so
if the ImportError is thrown, it will switch and import unittest2
which is a module that has backported the 2.7 unittest to older
versions of python.
'''
try:
    from unittest import loader
except ImportError:
    from unittest2 import loader

USAGE = """%prog
Run unit tests."""

parser = optparse.OptionParser(USAGE)
parser.add_option('-n',
                  '--name',
                  help='the name of the test to run',
                  metavar='NAME')

options, args = parser.parse_args()
sdk_path = None
if len(args) > 0:
    print 'Error: 0 arguments expected.'
    parser.print_help()
    sys.exit(1)

test_path = os.path.join(os.path.dirname(__file__), 'tests')
test_loader = loader.TestLoader()
if options.name: test_loader.testMethodPrefix = options.name
TextTestRunner(verbosity=2).run(test_loader.discover(test_path))
示例#6
0
from unittest import loader

start_path = ''
pattern = '*.py'

suites = loader.TestLoader().discover(start_path, pattern)
suites.run()
示例#7
0
        action='store_true',
        help=
        """Clear out the existing data, since we don't automatically do so at the end of a test"""
    )
    parser.add_argument("--verbose",
                        help="""whether the result output should be verbose""",
                        default=True)

    args = parser.parse_args()
    print(args)

    # spec = importlib.util.spec_from_file_location("realtests", args.test_file_path)
    # module = importlib.util.module_from_spec(spec)
    module = importlib.import_module(args.test_module)
    testcls = getattr(module, args.test_class)
    suite = loader.TestLoader().loadTestsFromTestCase(testcls)

    for (idx, test) in enumerate(suite):
        logging.info("Checking test %s: %s" % (idx, test._testMethodName))
        if args.test is not None and test._testMethodName == args.test:
            if args.clean:
                logging.info("Cleaning test %s: %s" %
                             (idx, test._testMethodName))
                test.branch = args.branch
                etc.fillExistingUUID(test)
                result = test.tearDown()
            else:
                logging.info("Running test %s: %s" %
                             (idx, test._testMethodName))
                test.evaluation = True
                test.persistence = True
示例#8
0
 def discover(self):
     self.suitedict = {}
     tests = loader.TestLoader().discover(self.casedir, 'test*.py', None)
     self.getsuite(tests)