forked from pallets/flask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-tests.py
57 lines (44 loc) · 1.57 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
import sys
import unittest
from unittest.loader import TestLoader
from flask.testsuite import suite
common_prefix = suite.__module__ + '.'
def find_all_tests():
suites = [suite()]
while suites:
s = suites.pop()
try:
suites.extend(s)
except TypeError:
yield s
def find_all_tests_with_name():
for testcase in find_all_tests():
yield testcase, '%s.%s.%s' % (
testcase.__class__.__module__,
testcase.__class__.__name__,
testcase._testMethodName
)
class BetterLoader(TestLoader):
def loadTestsFromName(self, name, module=None):
if name == 'suite':
return suite()
for testcase, testname in find_all_tests_with_name():
if testname == name:
return testcase
if testname.startswith(common_prefix):
if testname[len(common_prefix):] == name:
return testcase
all_results = []
for testcase, testname in find_all_tests_with_name():
if testname.endswith('.' + name):
all_results.append((testcase, testname))
if len(all_results) == 1:
return all_results[0][0]
elif not len(all_results):
error = 'could not find testcase "%s"' % name
else:
error = 'Too many matches: for "%s"\n%s' % \
(name, '\n'.join(' - ' + n for c, n in all_results))
print >> sys.stderr, 'Error: %s' % error
sys.exit(1)
unittest.main(testLoader=BetterLoader(), defaultTest='suite')