PageRenderTime 172ms CodeModel.GetById 30ms app.highlight 62ms RepoModel.GetById 59ms app.codeStats 0ms

/tests/runtests.py

http://django-evolution.googlecode.com/
Python | 62 lines | 43 code | 18 blank | 1 comment | 7 complexity | a6bddeb7a43e9d9dbd55c3ef485e8e18 MD5 | raw file
 1#!/usr/bin/env python
 2import nose
 3import os
 4import sys
 5
 6
 7def run_tests(verbosity=1, interactive=False):
 8    from django.conf import settings
 9    from django.core import management
10    from django.test.utils import setup_test_environment, \
11                                  teardown_test_environment
12
13    from django_evolution import is_multi_db
14
15    setup_test_environment()
16    settings.DEBUG = False
17
18    old_db_names = []
19
20    if is_multi_db():
21        from django.db import connections
22
23        for alias in connections:
24            connection = connections[alias]
25
26            old_db_names.append((connection, connection.settings_dict['NAME']))
27            connection.creation.create_test_db(verbosity,
28                                               autoclobber=not interactive)
29    else:
30        from django.db import connection
31
32        old_db_names.append((connection, settings.DATABASE_NAME))
33        connection.creation.create_test_db(verbosity,
34                                           autoclobber=not interactive)
35
36
37    management.call_command('syncdb', verbosity=verbosity,
38                            interactive=interactive)
39
40    nose_argv = ['runtests.py', '-v',
41                 '--with-coverage',
42                 '--with-doctest',
43                 '--doctest-extension=.txt',
44                 '--cover-package=django_evolution',
45                 '--match=tests[\/]*.py']
46
47    if len(sys.argv) > 2:
48        nose_argv += sys.argv[2:]
49
50    nose.run(argv=nose_argv)
51
52    for connection, name in old_db_names:
53        connection.creation.destroy_test_db(name, verbosity=0)
54
55    teardown_test_environment()
56
57
58if __name__ == "__main__":
59    os.chdir(os.path.join(os.path.dirname(__file__), ".."))
60    sys.path.insert(0, os.getcwd())
61    os.environ['DJANGO_SETTINGS_MODULE'] = "tests.settings"
62    run_tests()