File: alltests.py

package info (click to toggle)
pyhamcrest 1.6-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 556 kB
  • sloc: python: 2,938; makefile: 2
file content (32 lines) | stat: -rw-r--r-- 873 bytes parent folder | download
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
import os
import sys
import unittest

__author__ = "Jon Reid"
__copyright__ = "Copyright 2011 hamcrest.org"
__license__ = "BSD, see License.txt"

if __name__ == "__main__":
    sys.path.insert(0, '..')


def alltests():
    """Returns suite of all tests in this directory and below."""
    testloader = unittest.defaultTestLoader
    suite = testloader.suiteClass()

    fullpath = os.path.abspath(os.path.dirname(sys.argv[0]))
    for dirpath, dirnames, filenames in os.walk(fullpath):
        sys.path.insert(0, dirpath)
        for file in filenames:
            if file.endswith('test.py'):
                (name, ext) = os.path.splitext(file)
                module = __import__(name)
                suite.addTest(testloader.loadTestsFromModule(module))
        sys.path.pop(0)

    return suite


if __name__ == '__main__':
    unittest.main(defaultTest='alltests')