annotate tests/silenttestrunner.py @ 23172:e955549cd045

tests: write hgrc of more than two lines by using shell heredoc Here document should be readable than repeating echo commands.
author Yuya Nishihara <yuya@tcha.org>
date Tue, 04 Nov 2014 23:41:46 +0900
parents 2cbfb8c497ee
children dadcd40b62d8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18665
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
1 import unittest, sys
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
2
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
3 def main(modulename):
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
4 '''run the tests found in module, printing nothing when all tests pass'''
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
5 module = sys.modules[modulename]
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
6 suite = unittest.defaultTestLoader.loadTestsFromModule(module)
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
7 results = unittest.TestResult()
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
8 suite.run(results)
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
9 if results.errors or results.failures:
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
10 for tc, exc in results.errors:
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
11 print 'ERROR:', tc
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
12 print
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
13 sys.stdout.write(exc)
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
14 for tc, exc in results.failures:
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
15 print 'FAIL:', tc
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
16 print
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
17 sys.stdout.write(exc)
2cbfb8c497ee tests: add a test runner utility that prints nothing when all tests pass
Idan Kamara <idankk86@gmail.com>
parents:
diff changeset
18 sys.exit(1)