-
Notifications
You must be signed in to change notification settings - Fork 8
/
run_tests.py
66 lines (52 loc) · 1.54 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# Script lovingly influenced by the Pinax test running script
import optparse
import os
import sys
from django.conf import settings
from django.core.management import call_command
def setup_test_environment():
os.environ['PYTHONPATH'] = os.path.abspath(__file__)
settings.configure(**{
"DATABASES": {
"default": {
"ENGINE": "sqlite3",
},
},
"INSTALLED_APPS": ("djangosampler", ),
})
def main():
usage = "%prog [options]"
parser = optparse.OptionParser(usage=usage)
parser.add_option("-v", "--verbosity",
action = "store",
dest = "verbosity",
default = "0",
type = "choice",
choices = ["0", "1", "2"],
help = "verbosity level; 0=minimal output, 1=normal output, 2=all output",
)
parser.add_option("--coverage",
action = "store_true",
dest = "coverage",
default = False,
help = "hook in coverage during test suite run and save out results",
)
options, _ = parser.parse_args()
if options.coverage:
try:
import coverage
except ImportError:
sys.stderr.write("coverage is not installed.\n")
sys.exit(1)
else:
cov = coverage.coverage(auto_data=True)
cov.start()
else:
cov = None
setup_test_environment()
call_command("test", verbosity=int(options.verbosity))
if cov:
cov.stop()
cov.save()
if __name__ == "__main__":
main()