22unittest2
33
44unittest2 is a backport of the new features added to the unittest testing
5- framework in Python 2.7. It is tested to run on Python 2.4 - 2.6 .
5+ framework in Python 2.7 and beyond . It is tested to run on Python 2.4 - 2.7 .
66
77To use unittest2 instead of unittest simply replace ``import unittest`` with
88``import unittest2``.
3131 'defaultTestLoader' , 'SkipTest' , 'skip' , 'skipIf' , 'skipUnless' ,
3232 'expectedFailure' , 'TextTestResult' , '__version__' , 'collector' ]
3333
34- __version__ = '0.5 .1'
34+ __version__ = '1.0 .1'
3535
3636# Expose obsolete functions for backwards compatibility
3737__all__ .extend (['getTestCaseNames' , 'makeSuite' , 'findTestCases' ])
3838
3939
40- from python_toolbox . third_party . unittest2 .collector import collector
41- from python_toolbox . third_party . unittest2 .result import TestResult
42- from python_toolbox . third_party . unittest2 .case import (
40+ from unittest2 .collector import collector
41+ from unittest2 .result import TestResult
42+ from unittest2 .case import (
4343 TestCase , FunctionTestCase , SkipTest , skip , skipIf ,
4444 skipUnless , expectedFailure
4545)
46- from python_toolbox . third_party . unittest2 .suite import BaseTestSuite , TestSuite
47- from python_toolbox . third_party . unittest2 .loader import (
46+ from unittest2 .suite import BaseTestSuite , TestSuite
47+ from unittest2 .loader import (
4848 TestLoader , defaultTestLoader , makeSuite , getTestCaseNames ,
4949 findTestCases
5050)
51- from python_toolbox . third_party . unittest2 .main import TestProgram , main , main_
52- from python_toolbox . third_party . unittest2 .runner import TextTestRunner , TextTestResult
51+ from unittest2 .main import TestProgram , main
52+ from unittest2 .runner import TextTestRunner , TextTestResult
5353
5454try :
55- from python_toolbox . third_party . unittest2 .signals import (
55+ from unittest2 .signals import (
5656 installHandler , registerResult , removeResult , removeHandler
5757 )
5858except ImportError :
5959 # Compatibility with platforms that don't have the signal module
6060 pass
6161else :
62- __all__ .extend (['installHandler' , 'registerResult' , 'removeResult' ,
62+ __all__ .extend (['installHandler' , 'registerResult' , 'removeResult' ,
6363 'removeHandler' ])
6464
6565# deprecated
6666_TextTestResult = TextTestResult
6767
68- __unittest = True
68+ # There are no tests here, so don't try to run anything discovered from
69+ # introspecting the symbols (e.g. FunctionTestCase). Instead, all our
70+ # tests come from within unittest.test.
71+ def load_tests (loader , tests , pattern ):
72+ import os .path
73+ # top level directory cached on loader instance
74+ this_dir = os .path .dirname (__file__ )
75+ return loader .discover (start_dir = this_dir , pattern = pattern )
76+
77+ __unittest = True
78+
79+ def load_tests (loader , tests , pattern ):
80+ # All our tests are in test/ - the test objects found in unittest2 itself
81+ # are base classes not intended to be executed. This load_tests intercepts
82+ # discovery to prevent that.
83+ import unittest2 .test
84+ result = loader .suiteClass ()
85+ for path in unittest2 .test .__path__ :
86+ result .addTests (loader .discover (path , pattern = pattern ))
87+ return result
0 commit comments