| 1 |
#!/usr/bin/env python |
| 2 |
"""Run unittests in the `tests` directory.""" |
| 3 |
|
| 4 |
from optparse import OptionParser |
| 5 |
import sys |
| 6 |
|
| 7 |
try: |
| 8 |
import unittest2 as unittest |
| 9 |
except ImportError: |
| 10 |
import unittest |
| 11 |
|
| 12 |
def main(): |
| 13 |
parser = OptionParser() |
| 14 |
parser.add_option("-x", "--xml", action="store_true", dest="xml", |
| 15 |
help="write test report in xunit file format (requires xmlrunner==1.7.4)") |
| 16 |
(options, args) = parser.parse_args(sys.argv) |
| 17 |
loader = unittest.defaultTestLoader |
| 18 |
names = args[1:] |
| 19 |
if names: |
| 20 |
suite = loader.loadTestsFromNames(names) |
| 21 |
else: |
| 22 |
suite = loader.discover('test') |
| 23 |
if options.xml: |
| 24 |
import xmlrunner |
| 25 |
runner = xmlrunner.XMLTestRunner(output='build/test-reports') |
| 26 |
else: |
| 27 |
runner = unittest.TextTestRunner(verbosity=2) |
| 28 |
result = runner.run(suite) |
| 29 |
if result.wasSuccessful(): |
| 30 |
return 0 |
| 31 |
else: |
| 32 |
return 1 |
| 33 |
|
| 34 |
if __name__ == '__main__': |
| 35 |
sys.exit(main()) |