Esempio n. 1
0
def run(targets, options):
    "Imports and runs the modules names that are contained in the 'targets'"
    
    success = errors = skipped = 0

    import_modules = [ 'doc_tests' ]
    # run the tests by importing the module and getting its test suite
    for name in targets:
        try:

            if name in import_modules:
                mod = __import__(name)
                suite = mod.get_suite()
            else:
                loader = unittest.TestLoader()
                suite = loader.loadTestsFromName(name)

            runner = TestRunner(verbosity=options.verbosity,
                                    descriptions=0)
            
            results = runner.run(suite)
            
            # count tests and errors
            success += results.testsRun - \
                       len(results.errors) - \
                       len(results.failures) - \
                       len(results.skipped)
            
            errors  += len(results.errors) + len(results.failures)
            skipped += len(results.skipped)

            # if we're in strict mode stop on errors
            if options.strict and errors:
                testutil.error( "strict mode stops on errors" )
                break

        except ImportError:
            testutil.error( "unable to import module '%s'" % name )

    # enable the logger
    logger.disable(None)

    # summarize the run
    testutil.info('=' * 59)
    testutil.info('''%s tests passed, %s tests failed, %s tests skipped; %d total''' % \
        (success, errors, skipped, success + errors + skipped))

    return (success, errors, skipped)
Esempio n. 2
0
def run(targets, options):
    "Imports and runs the modules names that are contained in the 'targets'"

    success = errors = skipped = 0

    import_modules = ['doc_tests']
    # run the tests by importing the module and getting its test suite
    for name in targets:
        try:

            if name in import_modules:
                mod = __import__(name)
                suite = mod.get_suite()
            else:
                loader = unittest.TestLoader()
                suite = loader.loadTestsFromName(name)

            runner = TestRunner(verbosity=options.verbosity, descriptions=0)

            results = runner.run(suite)

            # count tests and errors
            success += results.testsRun - \
                       len(results.errors) - \
                       len(results.failures) - \
                       len(results.skipped)

            errors += len(results.errors) + len(results.failures)
            skipped += len(results.skipped)

            # if we're in strict mode stop on errors
            if options.strict and errors:
                testutil.error("strict mode stops on errors")
                break

        except ImportError:
            testutil.error("unable to import module '%s'" % name)

    # enable the logger
    logger.disable(None)

    # summarize the run
    testutil.info('=' * 59)
    testutil.info('''%s tests passed, %s tests failed, %s tests skipped; %d total''' % \
        (success, errors, skipped, success + errors + skipped))

    return (success, errors, skipped)
Esempio n. 3
0
def run(targets, options):
    "Imports and runs the modules names that are contained in the 'targets'"

    success = errors = skipped = 0

    # run the tests by importing the module and getting its test suite
    for name in targets:
        try:
            testutil.info('running tests for module %s' % name)
            l = unittest.TestLoader()
            suite = l.loadTestsFromName(name)

            runner = PygrTestRunner(verbosity=options.verbosity,
                                    descriptions=0)

            logger.disable(disable_threshold)  # set global override
            results = runner.run(suite)
            logger.disable(0)                  # clear global override

            # count tests and errors
            success += results.testsRun - \
                       len(results.errors) - \
                       len(results.failures) - \
                       len(results.skipped)

            errors += len(results.errors) + len(results.failures)
            skipped += len(results.skipped)

            # if we're in strict mode stop on errors
            if options.strict and errors:
                testutil.error("strict mode stops on errors")
                break

        except ImportError:
            testutil.error("unable to import module '%s'" % name)

    # summarize the run
    testutil.info('=' * 59)
    testutil.info('''\
%s tests passed, %s tests failed, %s tests skipped; %d total''' % \
                  (success, errors, skipped, success + errors + skipped))

    return (success, errors, skipped)