forked from Suor/django-cacheops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_tests.py
executable file
·30 lines (25 loc) · 1.02 KB
/
run_tests.py
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
#!/usr/bin/env python
import os, sys, re, shutil
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
import django
from django.core.management import call_command
names_prefix = 'tests.tests' if django.VERSION >= (1, 6) else 'tests'
names = next((a for a in sys.argv[1:] if not a.startswith('-')), None)
if names and re.search(r'^\d+$', names):
names = names_prefix + '.IssueTests.test_' + names
elif names and not names.startswith('tests.'):
names = names_prefix + '.' + names
else:
names = names_prefix
if hasattr(django, 'setup'):
django.setup()
# NOTE: we create migrations each time since they depend on type of database,
# python and django versions
try:
if django.VERSION >= (1, 7):
shutil.rmtree('tests/migrations', True)
call_command('makemigrations', 'tests', verbosity=2 if '-v' in sys.argv else 0)
call_command('test', names, failfast='-x' in sys.argv, verbosity=2 if '-v' in sys.argv else 1)
finally:
if django.VERSION >= (1, 7):
shutil.rmtree('tests/migrations')