Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 67 lines (55 sloc) 2.14 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
#!/usr/bin/env python
import optparse
import os
import sys
import unittest

def collect():
    import tests
    runtests(tests, 1)

def runtests(module, verbosity):
    suite = unittest.TestLoader().loadTestsFromModule(module)
    results = unittest.TextTestRunner(verbosity=verbosity).run(suite)
    return results.failures, results.errors

def get_option_parser():
    parser = optparse.OptionParser()
    parser.add_option('-e', '--engine', dest='engine', default='sqlite', help='Database engine to test, one of [sqlite3, postgres, mysql]')
    parser.add_option('-v', '--verbosity', dest='verbosity', default=1, type='int', help='Verbosity of output')
    parser.add_option('-a', '--all', dest='all', default=False, action='store_true', help='Run all tests, including extras')
    parser.add_option('-x', '--extra', dest='extra', default=False, action='store_true', help='Run only extras tests')
    return parser

if __name__ == '__main__':
    parser = get_option_parser()
    options, args = parser.parse_args()

    os.environ['PEEWEE_TEST_BACKEND'] = options.engine
    os.environ['PEEWEE_TEST_VERBOSITY'] = str(options.verbosity)

    import tests

    if options.all or options.extra:
        modules = [tests]
        from playhouse import tests as extras_tests
        modules.append(extras_tests)
        try:
            from playhouse import tests_apsw
            modules.append(tests_apsw)
        except ImportError:
            print 'Unable to import apsw tests, skipping'

        try:
            from playhouse import tests_postgres
            modules.append(tests_postgres)
        except ImportError:
            print 'Unable to import postgres_ext tests, skipping'
    else:
        modules = [tests]

    if options.extra:
        modules.remove(tests)

    results = []
    any_failures = False
    any_errors = False
    for module in modules:
        failures, errors = runtests(module, options.verbosity)
        any_failures = any_failures or bool(failures)
        any_errors = any_errors or bool(errors)

    if any_errors:
        sys.exit(2)
    elif any_failures:
        sys.exit(1)
    sys.exit(0)
Something went wrong with that request. Please try again.