-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrun_tests
executable file
·69 lines (56 loc) · 1.72 KB
/
run_tests
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
#!/usr/bin/env python
"""Runs the tests for pyexperiment
Written by Peter Duerr
"""
from __future__ import print_function
from __future__ import unicode_literals
from __future__ import division
from __future__ import absolute_import
import unittest
import sys
import multiprocessing
# Make sure matplotlib is using backend for headless testing
import matplotlib
matplotlib.use('Agg')
def covered_process():
"""Monkey patches the multiprocessing module to start coverage
"""
try:
from coverage.collector import Collector
from coverage import coverage
except ImportError:
return None
# detect if coverage was running in forked process
# pylint: disable=protected-access
if Collector._collectors:
original = multiprocessing.Process._bootstrap
class ProcessWithCoverage(multiprocessing.Process):
"""Monkey patched process
"""
def _bootstrap(self):
cov = coverage(data_suffix=True,
include="pyexperiment/*.py")
cov.start()
try:
return original(self)
finally:
cov.stop()
cov.save()
return ProcessWithCoverage
PROCESS_WITH_COVERAGE = covered_process()
if PROCESS_WITH_COVERAGE:
multiprocessing.Process = PROCESS_WITH_COVERAGE
def main(argv):
"""Runs all the tests
"""
verbosity = 1
if '-v' in argv:
verbosity = 2
suite = unittest.TestLoader().discover('tests')
return unittest.TextTestRunner(verbosity=verbosity).run(suite)
if __name__ == "__main__":
result = main(sys.argv)
if result.wasSuccessful():
exit(0)
else:
exit(1)