blob: 0fbd3b83f75982b78314f2575a0a83e41d91ebe7 [file] [log] [blame]
cliechti5eb4b892009-08-07 18:21:58 +00001#! /usr/bin/env python
2
3"""\
4UnitTest runner. This one searches for all files named test_*.py and collects
5all test cases from these files. Finally it runs all tests and prints a
6summary.
7"""
8
9import unittest
10import sys
11import os
12import time
13
cliechti82282e02009-08-07 18:49:40 +000014# inject local copy to avoid testing the installed version instead of the
Chris Liechti418a2222015-08-03 17:20:12 +020015sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
cliechti82282e02009-08-07 18:49:40 +000016
cliechti59dff672010-01-02 03:03:29 +000017import serial
cliechtie30868d2013-10-16 15:35:11 +000018print("Patching sys.path to test local version. Testing Version: %s" % (serial.VERSION,))
cliechti59dff672010-01-02 03:03:29 +000019
cliechti5eb4b892009-08-07 18:21:58 +000020PORT = 'loop://'
cliechti59dff672010-01-02 03:03:29 +000021if len(sys.argv) > 1:
22 PORT = sys.argv[1]
cliechti5eb4b892009-08-07 18:21:58 +000023
24# find files and the tests in them
25mainsuite = unittest.TestSuite()
Chris Liechti418a2222015-08-03 17:20:12 +020026for modulename in [
27 os.path.splitext(x)[0]
28 for x in os.listdir(os.path.dirname(__file__))
cliechti1f4abd72010-07-01 12:56:38 +000029 if x != __file__ and x.startswith("test") and x.endswith(".py")
cliechti5eb4b892009-08-07 18:21:58 +000030]:
31 try:
32 module = __import__(modulename)
33 except ImportError:
cliechtie30868d2013-10-16 15:35:11 +000034 print("skipping %s" % (modulename,))
cliechti5eb4b892009-08-07 18:21:58 +000035 else:
36 module.PORT = PORT
37 testsuite = unittest.findTestCases(module)
cliechtie30868d2013-10-16 15:35:11 +000038 print("found %s tests in %r" % (testsuite.countTestCases(), modulename))
cliechti5eb4b892009-08-07 18:21:58 +000039 mainsuite.addTest(testsuite)
40
41verbosity = 1
42if '-v' in sys.argv[1:]:
43 verbosity = 2
44
45# run the collected tests
46testRunner = unittest.TextTestRunner(verbosity=verbosity)
47#~ testRunner = unittest.ConsoleTestRunner(verbosity=verbosity)
48result = testRunner.run(mainsuite)
49
50# set exit code accordingly to test results
51sys.exit(not result.wasSuccessful())