-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathruntests.py
executable file
·28 lines (22 loc) · 1017 Bytes
/
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
#!/usr/bin/env python3
import unittest
def runtests(processes=4):
"""
Run Bitfield's unit tests. Will run the tests in parallel if the `concurrencytest` library
is installed. Will run serially otherwise.
"""
# Discover all tests in the current directory that are prefixed with `test`. Also discovers
# the doctests loaded by defining a load_tests(...) function in the module __init__.py
loader = unittest.TestLoader()
doctest_suite = loader.discover('.', pattern='test*.py')
runner = unittest.runner.TextTestRunner()
try:
from concurrencytest import ConcurrentTestSuite, fork_for_tests
concurrent_doctest_suite = ConcurrentTestSuite(doctest_suite, fork_for_tests(processes))
runner.run(concurrent_doctest_suite)
except ImportError:
runner.run(doctest_suite)
# Prevent calling sys.exit() just in case the user is running the tests from an interpreter.
unittest.main(exit=False)
if __name__ == '__main__':
runtests()