annotate tests/silenttestrunner.py @ 18665:2cbfb8c497ee

tests: add a test runner utility that prints nothing when all tests pass This will be used to run tests through run-tests, which will expect no output for a unit test that passes successfully. The motivation for using unit tests instead of the current Python tests is that they don't require an output file for comparison and that they're easier to write because of the available tools from unittest (setup, asserts).
author Idan Kamara <idankk86@gmail.com>
date Sat, 09 Feb 2013 19:13:39 +0200
parents
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)