File: testsuite.py

package info (click to toggle)
jaydebeapi 1.2.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 292 kB
  • sloc: python: 963; java: 188; xml: 62; sh: 53; sql: 27; makefile: 3
file content (35 lines) | stat: -rw-r--r-- 959 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
33
34
35
#!/usr/bin/env python
"""Run unittests in the `tests` directory."""

from optparse import OptionParser
import sys

try:
    import unittest2 as unittest
except ImportError:
    import unittest

def main():
    parser = OptionParser()
    parser.add_option("-x", "--xml", action="store_true", dest="xml",
                  help="write test report in xunit file format (requires xmlrunner==1.7.4)")
    (options, args) = parser.parse_args(sys.argv)
    loader = unittest.defaultTestLoader
    names = args[1:]
    if names:
        suite = loader.loadTestsFromNames(names)
    else:
        suite = loader.discover('test')
    if options.xml:
        import xmlrunner
        runner = xmlrunner.XMLTestRunner(output='build/test-reports')
    else:
        runner = unittest.TextTestRunner(verbosity=2)
    result = runner.run(suite)
    if result.wasSuccessful():
        return 0
    else:
        return 1
    
if __name__ == '__main__':
    sys.exit(main())