forked from Suor/django-cacheops
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_tests.py
executable file
·42 lines (34 loc) · 1.14 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
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
import os, sys, re, shutil
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
# Use psycopg2cffi for PyPy
try:
import psycopg2 # noqa
except ImportError:
# Fall back to psycopg2cffi
try:
from psycopg2cffi import compat
compat.register()
except ImportError:
# Hope we are not testing against PostgreSQL :)
pass
# Set up Django
import django
from django.core.management import call_command
django.setup()
# Derive test names
names = next((a for a in sys.argv[1:] if not a.startswith('-')), None)
if not names:
names = 'tests'
elif re.search(r'^\d+', names):
names = 'tests.tests.IssueTests.test_' + names
elif not names.startswith('tests.'):
names = 'tests.tests.' + names
# NOTE: we create migrations each time since they depend on type of database,
# python and django versions
try:
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:
shutil.rmtree('tests/migrations', True)