diff options
author | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2009-08-07 18:21:58 +0000 |
---|---|---|
committer | cliechti <cliechti@f19166aa-fa4f-0410-85c2-fa1106f25c8a> | 2009-08-07 18:21:58 +0000 |
commit | 93bfe4f43975cf7f6af788b863a1fec7c2379f32 (patch) | |
tree | 9c91f9be72bfd6e2a16873650fa314fd5f23af1d /examples | |
parent | b84aa9219fdc57ff7c62c9b9bcb848e8c4f7b230 (diff) | |
download | pyserial-93bfe4f43975cf7f6af788b863a1fec7c2379f32.tar.gz |
- script to run all the tests
- don't print warning if test module is not main module
git-svn-id: http://svn.code.sf.net/p/pyserial/code/trunk/pyserial@319 f19166aa-fa4f-0410-85c2-fa1106f25c8a
Diffstat (limited to 'examples')
-rw-r--r-- | examples/run_all_tests.py | 42 | ||||
-rw-r--r-- | examples/test_iolib.py | 2 |
2 files changed, 43 insertions, 1 deletions
diff --git a/examples/run_all_tests.py b/examples/run_all_tests.py new file mode 100644 index 0000000..636a0b6 --- /dev/null +++ b/examples/run_all_tests.py @@ -0,0 +1,42 @@ +#! /usr/bin/env python + +"""\ +UnitTest runner. This one searches for all files named test_*.py and collects +all test cases from these files. Finally it runs all tests and prints a +summary. +""" + +import unittest +import sys +import os +import time + +PORT = 'loop://' + +# find files and the tests in them +mainsuite = unittest.TestSuite() +for modulename in [os.path.splitext(x)[0] + for x in os.listdir('.') + if x != __file__ and x.startswith("test_") and x.endswith(".py") +]: + try: + module = __import__(modulename) + except ImportError: + print "skipping %s" % modulename + else: + module.PORT = PORT + testsuite = unittest.findTestCases(module) + print "found %s tests in %r" % (testsuite.countTestCases(), modulename) + mainsuite.addTest(testsuite) + +verbosity = 1 +if '-v' in sys.argv[1:]: + verbosity = 2 + +# run the collected tests +testRunner = unittest.TextTestRunner(verbosity=verbosity) +#~ testRunner = unittest.ConsoleTestRunner(verbosity=verbosity) +result = testRunner.run(mainsuite) + +# set exit code accordingly to test results +sys.exit(not result.wasSuccessful()) diff --git a/examples/test_iolib.py b/examples/test_iolib.py index 5bcaed3..d4e9315 100644 --- a/examples/test_iolib.py +++ b/examples/test_iolib.py @@ -29,7 +29,7 @@ On a 9 pole DSUB these are the pins (2-3) (4-6) (7-8) import unittest import sys -if sys.version_info < (2, 6): +if __name__ == '__main__' and sys.version_info < (2, 6): sys.stderr.write("""\ ============================================================================== WARNING: this test is intended for Python 2.6 and newer where the io library |