This repository has been archived by the owner on Jan 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
run_integration_tests.py
executable file
·75 lines (54 loc) · 1.97 KB
/
run_integration_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
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
import sys
import logging
import unittest
from argparse import ArgumentParser
from distutils.core import Command
from importlib import import_module
from pathlib import Path
def run_tests(filenames=None, debug=False):
"""
Find and run all tests in the tests/ directory.
Excludes live tests (tests/live_*).
"""
if sys.version_info < (3, 8):
raise ValueError('Your python version is too old to run these tests')
if not filenames:
filenames = [i for i in Path('itests').glob('test_*')]
else:
filenames = [Path(i) for i in filenames]
modules = ['.'.join(test.parts[:-1] + (test.stem,)) for test in filenames]
suites = []
for filename in modules:
module = import_module(filename)
suites.append(module.suite)
tests = unittest.TestSuite(suites)
runner = unittest.TextTestRunner(verbosity=2)
if debug:
logging.basicConfig(level='DEBUG')
else:
# Disable logging output
logging.basicConfig(level=100)
logging.disable(100)
result = runner.run(tests)
return result
# Add a 'test' command for setup.py
class TestCommand(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
run_tests()
if __name__ == '__main__':
parser = ArgumentParser(description='Run unit tests.')
parser.add_argument('tests', metavar='TEST', nargs='*', help='list of tests to run, or nothing to run them all')
parser.add_argument('-d', '--debug', action='store_true', dest='debug', default=False, help='enable debug output')
args = parser.parse_args()
result = run_tests(args.tests, args.debug)
print("<tests %s ran='%s' errors='%s' fails='%s' success='%s'/>" % (
"xmlns='http//andyet.net/protocol/tests'",
result.testsRun, len(result.errors),
len(result.failures), result.wasSuccessful()))
sys.exit(not result.wasSuccessful())