1 """Generic test runner.
3 This module scans for filenames begining with test_ and runs the tests
4 in them. It is less noisy than the default Python test runners.
7 from __future__
import division
8 from __future__
import print_function
15 from unittest
import TestCase
20 for name
in glob
.glob(os
.path
.join(os
.path
.dirname(__file__
), "test_*.py")):
21 module
= "tests." + os
.path
.basename(name
)
22 __import__(module
[:-3], {}, {}, [])
24 class Result(unittest
.TestResult
):
29 def addSuccess(self
, test
):
30 unittest
.TestResult
.addSuccess(self
, test
)
33 def addError(self
, test
, err
):
34 unittest
.TestResult
.addError(self
, test
, err
)
37 def addFailure(self
, test
, err
):
38 unittest
.TestResult
.addFailure(self
, test
, err
)
41 def printErrors(self
):
42 succ
= self
.testsRun
- (len(self
.errors
) + len(self
.failures
))
44 count
= 50 - self
.testsRun
45 sys
.stdout
.write((" " * count
) + v
+ "\n")
46 self
.printErrorList('ERROR', self
.errors
)
47 self
.printErrorList('FAIL', self
.failures
)
49 def printErrorList(self
, flavour
, errors
):
50 for test
, err
in errors
:
51 sys
.stdout
.write(self
.separator1
+ "\n")
52 sys
.stdout
.write("%s: %s\n" % (flavour
, str(test
)))
53 sys
.stdout
.write(self
.separator2
+ "\n")
54 sys
.stdout
.write("%s\n" % err
)
58 suite
= unittest
.makeSuite(test
)
59 pref
= '%s (%d): ' % (test
.__name
__, len(suite
._tests
))
60 print(pref
+ " " * (25 - len(pref
)), end
=" ")
64 return bool(result
.failures
+ result
.errors
)
70 if not run
or test
.__name
__ in run
or test
.__name
__.lstrip("T") in run
:
71 failures |
= runner
.run(test
)