-
Notifications
You must be signed in to change notification settings - Fork 38
/
runtests.py
81 lines (74 loc) · 2.4 KB
/
runtests.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python
import logging
import os
import subprocess
import sys
from argparse import ArgumentParser
import django
from celery import Celery
from django.conf import settings
from django.test.utils import get_runner
# needs additional dependencies
# pip install -r tests/requirements.txt
# must be run from the tracker root folder, for now
if __name__ == '__main__':
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.test_settings'
django.setup()
app = Celery()
app.config_from_object(
{
'task_always_eager': True,
}
)
logging.getLogger('post_office').disabled = True
parser = ArgumentParser()
# stolen from run test command
parser.add_argument(
'args',
metavar='test_label',
nargs='*',
help='Module paths to test; can be modulename, modulename.TestCase or modulename.TestCase.test_method',
)
parser.add_argument(
'--noinput',
'--no-input',
action='store_false',
dest='interactive',
default=True,
help='Tells Django to NOT prompt the user for input of any kind.',
)
if django.VERSION < (5, 1, 0):
parser.add_argument(
'--failfast',
action='store_true',
dest='failfast',
default=False,
help='Tells Django to stop running the test suite after first failed test.',
)
parser.add_argument(
'--nobundle',
'--no-bundle',
action='store_false',
dest='bundle',
default=True,
help='Tells Django to skip building the js bundles.',
)
TestRunner = get_runner(settings, 'xmlrunner.extra.djangotestrunner.XMLTestRunner')
TestRunner.add_arguments(parser)
parsed = parser.parse_args(sys.argv[1:])
test_runner = TestRunner(**parsed.__dict__)
if parsed.bundle:
try:
subprocess.check_call(
['yarn', 'build'],
env={**os.environ, 'NODE_ENV': 'development', 'NO_HMR': '1'},
)
except subprocess.SubprocessError:
# maybe failed because the modules aren't installed
subprocess.check_call(['yarn', '--immutable'])
subprocess.check_call(
['yarn', 'build'],
env={**os.environ, 'NODE_ENV': 'development', 'NO_HMR': '1'},
)
failures = test_runner.run_tests(parsed.args or ['tests'])
sys.exit(bool(failures))