Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
| 3 | import os |
| 4 | import sys |
| 5 | from optparse import OptionParser |
| 6 | |
| 7 | |
| 8 | def parse_args(): |
| 9 | parser = OptionParser() |
| 10 | parser.add_option('-s', '--settings', help='Define settings.') |
| 11 | parser.add_option('-t', '--unittest', help='Define which test to run. Default all.') |
| 12 | options, args = parser.parse_args() |
| 13 | |
| 14 | if not options.settings: |
| 15 | parser.print_help() |
| 16 | sys.exit(1) |
| 17 | |
| 18 | if not options.unittest: |
| 19 | options.unittest = ['aggregation'] |
| 20 | |
| 21 | return options |
| 22 | |
| 23 | |
| 24 | def get_runner(settings_module): |
| 25 | ''' |
| 26 | Asks Django for the TestRunner defined in settings or the default one. |
| 27 | ''' |
| 28 | os.environ['DJANGO_SETTINGS_MODULE'] = settings_module |
| 29 | |
| 30 | import django |
| 31 | from django.test.utils import get_runner |
| 32 | from django.conf import settings |
| 33 | |
| 34 | if hasattr(django, 'setup'): |
| 35 | django.setup() |
| 36 | |
| 37 | return get_runner(settings) |
| 38 | |
| 39 | |
| 40 | def runtests(): |
| 41 | options = parse_args() |
| 42 | TestRunner = get_runner(options.settings) |
| 43 | runner = TestRunner(verbosity=1, interactive=True, failfast=False) |
| 44 | sys.exit(runner.run_tests([])) |
| 45 | |
| 46 | |
| 47 | if __name__ == '__main__': |
| 48 | runtests() |