Ignore:
Timestamp:
Nov 27, 2015, 11:45:53 AM (4 years ago)
Author:
cito
Message:

Use unittest2 in test_classic

Also, depending on how the tests are started, relative imports may
fail, so use absolute imports if that happens.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.x/module/tests/test_classic.py

    r647 r648  
    22
    33from __future__ import with_statement
     4
     5try:
     6    import unittest2 as unittest  # for Python < 2.7
     7except ImportError:
     8    import unittest
    49
    510import sys
     
    712from time import sleep
    813from threading import Thread
    9 import unittest
     14
    1015from pg import *
    1116
     
    346351
    347352if __name__ == '__main__':
    348     suite = unittest.TestSuite()
    349 
    350     if len(sys.argv) > 1: test_list = sys.argv[1:]
    351     else: test_list = unittest.getTestCaseNames(UtilityTest, 'test_')
    352 
    353353    if len(sys.argv) == 2 and sys.argv[1] == '-l':
    354354        print '\n'.join(unittest.getTestCaseNames(UtilityTest, 'test_'))
    355         sys.exit(1)
    356 
     355        sys.exit(0)
     356
     357    test_list = [name for name in sys.argv[1:] if not name.startswith('-')]
     358    if not test_list:
     359        test_list = unittest.getTestCaseNames(UtilityTest, 'test_')
     360
     361    suite = unittest.TestSuite()
    357362    for test_name in test_list:
    358363        try:
    359364            suite.addTest(UtilityTest(test_name))
    360         except:
     365        except Exception:
    361366            print "\n ERROR: %s.\n" % sys.exc_value
    362367            sys.exit(1)
    363368
    364     rc = unittest.TextTestRunner(verbosity=1).run(suite)
    365     sys.exit(len(rc.errors+rc.failures) != 0)
    366 
     369    verbosity = '-v' in sys.argv[1:] and 2 or 1
     370    failfast = '-l' in sys.argv[1:]
     371    runner = unittest.TextTestRunner(verbosity=verbosity, failfast=failfast)
     372    rc = runner.run(suite)
     373    sys.exit(1 if rc.errors or rc.failures else 0)
Note: See TracChangeset for help on using the changeset viewer.