silenttestrunner.py
24 lines
| 734 B
| text/x-python
|
PythonLexer
/ tests / silenttestrunner.py
|
r28730 | from __future__ import absolute_import, print_function | ||
|
r28736 | import os | ||
import sys | ||||
|
r28729 | import unittest | ||
|
r18665 | |||
def main(modulename): | ||||
'''run the tests found in module, printing nothing when all tests pass''' | ||||
module = sys.modules[modulename] | ||||
suite = unittest.defaultTestLoader.loadTestsFromModule(module) | ||||
results = unittest.TestResult() | ||||
suite.run(results) | ||||
if results.errors or results.failures: | ||||
for tc, exc in results.errors: | ||||
|
r28730 | print('ERROR:', tc) | ||
print() | ||||
|
r18665 | sys.stdout.write(exc) | ||
for tc, exc in results.failures: | ||||
|
r28730 | print('FAIL:', tc) | ||
print() | ||||
|
r18665 | sys.stdout.write(exc) | ||
sys.exit(1) | ||||
|
r23308 | |||
if os.environ.get('SILENT_BE_NOISY'): | ||||
main = unittest.main | ||||