-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathruntests.py
52 lines (46 loc) · 1.64 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
import os
import unittest
import sys
from tests.utils.runtest import makesuite, run
def GetFailedImportTestSuite(name, e):
class FailedImportTest(unittest.TestCase):
def testFailedImport(self):
raise Exception("could not import %s:\n%s" % (name, e))
return makesuite(FailedImportTest)
def CreateSuite():
suite = unittest.TestSuite()
for f in os.listdir("tests"):
if f.endswith("test.py"):
name = f[:-3]
try:
print("adding: tests.%s" % name)
m = __import__("tests.%s" % name)
suite.addTest(getattr(m, name).suite)
except Exception as e:
suite.addTest(GetFailedImportTestSuite(name, e))
return suite
# If run with a parameter, try to use it as a test selection
# (as specified in unittest, loadTestsFromName)
#
# Example 1 - run an individual test
# ipy runtests.py tests.baseobjecttest.NewInitFunctionsTest.test_PyObject_Newrun
#
# Example 2 - run all tests from a module
# ipy runtests.py tests.itertest
#
# If testing out-of-source builds, add argument «configuration»/«framework»
# as last argument on the command line
#
# Example 3 - run an individual test for configuration 'release', framework 'net462'
# ipy runtests.py tests.dicttest.DictTest release/net462
#
# Example 4 - run all tests for configuration 'release', framework 'net462'
# ipy runtests.py release/net462
#
# TODO: selecting decorated function does not work
if __name__ == '__main__':
if len(sys.argv) == 2:
suite = unittest.defaultTestLoader.loadTestsFromName(sys.argv[1])
else:
suite = CreateSuite()
run(suite, verbosity=2)