Staging
v0.5.1
https://github.com/python/cpython
Raw File
Tip revision: 8cee0cc3fea74f9abcb0ce343a86fa4c71673ead authored by Ned Deily on 06 September 2017, 07:23:33 UTC
Bump to 3.3.7rc1
Tip revision: 8cee0cc
__init__.py
import os
import sys
from test import support
import unittest

def test_suite(package=__package__, directory=os.path.dirname(__file__)):
    suite = unittest.TestSuite()
    for name in os.listdir(directory):
        if name.startswith(('.', '__')):
            continue
        path = os.path.join(directory, name)
        if (os.path.isfile(path) and name.startswith('test_') and
                name.endswith('.py')):
            submodule_name = os.path.splitext(name)[0]
            module_name = "{0}.{1}".format(package, submodule_name)
            __import__(module_name, level=0)
            module_tests = unittest.findTestCases(sys.modules[module_name])
            suite.addTest(module_tests)
        elif os.path.isdir(path):
            package_name = "{0}.{1}".format(package, name)
            __import__(package_name, level=0)
            package_tests = getattr(sys.modules[package_name], 'test_suite')()
            suite.addTest(package_tests)
        else:
            continue
    return suite


def test_main():
    start_dir = os.path.dirname(__file__)
    top_dir = os.path.dirname(os.path.dirname(start_dir))
    test_loader = unittest.TestLoader()
    support.run_unittest(test_loader.discover(start_dir, top_level_dir=top_dir))
back to top