mirror of
https://github.com/python/cpython.git
synced 2025-08-15 22:30:42 +00:00
Merged revisions 86101 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r86101 | michael.foord | 2010-11-01 21:09:03 +0000 (Mon, 01 Nov 2010) | 1 line Fix issue 9926. TestSuite subclasses that override __call__ are called correctly. ........
This commit is contained in:
parent
68c3678253
commit
e5dc24e874
4 changed files with 34 additions and 19 deletions
|
@ -35,6 +35,7 @@ class TestResult(object):
|
||||||
formatted traceback of the error that occurred.
|
formatted traceback of the error that occurred.
|
||||||
"""
|
"""
|
||||||
_previousTestClass = None
|
_previousTestClass = None
|
||||||
|
_testRunEntered = False
|
||||||
_moduleSetUpFailed = False
|
_moduleSetUpFailed = False
|
||||||
def __init__(self, stream=None, descriptions=None, verbosity=None):
|
def __init__(self, stream=None, descriptions=None, verbosity=None):
|
||||||
self.failfast = False
|
self.failfast = False
|
||||||
|
|
|
@ -80,23 +80,11 @@ class TestSuite(BaseTestSuite):
|
||||||
subclassing, do not forget to call the base class constructor.
|
subclassing, do not forget to call the base class constructor.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def run(self, result, debug=False):
|
||||||
|
topLevel = False
|
||||||
|
if getattr(result, '_testRunEntered', False) is False:
|
||||||
|
result._testRunEntered = topLevel = True
|
||||||
|
|
||||||
def run(self, result):
|
|
||||||
self._wrapped_run(result)
|
|
||||||
self._tearDownPreviousClass(None, result)
|
|
||||||
self._handleModuleTearDown(result)
|
|
||||||
return result
|
|
||||||
|
|
||||||
def debug(self):
|
|
||||||
"""Run the tests without collecting errors in a TestResult"""
|
|
||||||
debug = _DebugResult()
|
|
||||||
self._wrapped_run(debug, True)
|
|
||||||
self._tearDownPreviousClass(None, debug)
|
|
||||||
self._handleModuleTearDown(debug)
|
|
||||||
|
|
||||||
################################
|
|
||||||
# private methods
|
|
||||||
def _wrapped_run(self, result, debug=False):
|
|
||||||
for test in self:
|
for test in self:
|
||||||
if result.shouldStop:
|
if result.shouldStop:
|
||||||
break
|
break
|
||||||
|
@ -111,13 +99,23 @@ class TestSuite(BaseTestSuite):
|
||||||
getattr(result, '_moduleSetUpFailed', False)):
|
getattr(result, '_moduleSetUpFailed', False)):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if hasattr(test, '_wrapped_run'):
|
if not debug:
|
||||||
test._wrapped_run(result, debug)
|
|
||||||
elif not debug:
|
|
||||||
test(result)
|
test(result)
|
||||||
else:
|
else:
|
||||||
test.debug()
|
test.debug()
|
||||||
|
|
||||||
|
if topLevel:
|
||||||
|
self._tearDownPreviousClass(None, result)
|
||||||
|
self._handleModuleTearDown(result)
|
||||||
|
return result
|
||||||
|
|
||||||
|
def debug(self):
|
||||||
|
"""Run the tests without collecting errors in a TestResult"""
|
||||||
|
debug = _DebugResult()
|
||||||
|
self.run(debug, True)
|
||||||
|
|
||||||
|
################################
|
||||||
|
|
||||||
def _handleClassSetUp(self, test, result):
|
def _handleClassSetUp(self, test, result):
|
||||||
previousClass = getattr(result, '_previousTestClass', None)
|
previousClass = getattr(result, '_previousTestClass', None)
|
||||||
currentClass = test.__class__
|
currentClass = test.__class__
|
||||||
|
|
|
@ -345,5 +345,19 @@ class Test_TestSuite(unittest.TestCase, TestEquality):
|
||||||
self.assertEqual(result.testsRun, 2)
|
self.assertEqual(result.testsRun, 2)
|
||||||
|
|
||||||
|
|
||||||
|
def test_overriding_call(self):
|
||||||
|
class MySuite(unittest.TestSuite):
|
||||||
|
called = False
|
||||||
|
def __call__(self, *args, **kw):
|
||||||
|
self.called = True
|
||||||
|
unittest.TestSuite.__call__(self, *args, **kw)
|
||||||
|
|
||||||
|
suite = MySuite()
|
||||||
|
wrapper = unittest.TestSuite()
|
||||||
|
wrapper.addTest(suite)
|
||||||
|
wrapper(unittest.TestResult())
|
||||||
|
self.assertTrue(suite.called)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
@ -66,6 +66,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue 120176: Wrapped TestSuite subclass does not get __call__ executed
|
||||||
|
|
||||||
- Issue 6706: asyncore accept() method no longer raises EWOULDBLOCK/ECONNABORTED
|
- Issue 6706: asyncore accept() method no longer raises EWOULDBLOCK/ECONNABORTED
|
||||||
on incomplete connection attempt but returns None instead.
|
on incomplete connection attempt but returns None instead.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue