testtools-dev team mailing list archive
-
testtools-dev team
-
Mailing list archive
-
Message #00306
[Merge] lp:~jml/testtools/cleanups-to-runtest into lp:testtools
Jonathan Lange has proposed merging lp:~jml/testtools/cleanups-to-runtest into lp:testtools.
Requested reviews:
testtools developers (testtools-dev)
Related bugs:
#662647 Move responsibility for running cleanups to RunTest
https://bugs.launchpad.net/bugs/662647
Very simple move of TestCase._runCleanups to RunTest._run_cleanups. The motivation is that it is more consistent with the existing behaviour, and that DeferredRunTest needed to be responsible for it anyway.
--
https://code.launchpad.net/~jml/testtools/cleanups-to-runtest/+merge/42001
Your team testtools developers is requested to review the proposed merge of lp:~jml/testtools/cleanups-to-runtest into lp:testtools.
=== modified file 'NEWS'
--- NEWS 2010-11-25 11:32:24 +0000
+++ NEWS 2010-11-27 10:55:33 +0000
@@ -10,6 +10,10 @@
* addUnexpectedSuccess is translated to addFailure for test results that don't
know about addUnexpectedSuccess. (Jonathan Lange, #654474)
+* Responsibility for running test cleanups has been moved to ``RunTest``.
+ This change does not affect public APIs and can be safely ignored by test
+ authors. (Jonathan Lange, #662647)
+
Improvements
------------
=== modified file 'testtools/__init__.py'
--- testtools/__init__.py 2010-10-31 20:37:49 +0000
+++ testtools/__init__.py 2010-11-27 10:55:33 +0000
@@ -32,11 +32,11 @@
Matcher,
)
from testtools.runtest import (
+ MultipleExceptions,
RunTest,
)
from testtools.testcase import (
ErrorHolder,
- MultipleExceptions,
PlaceHolder,
TestCase,
clone_test_with_new_id,
=== modified file 'testtools/runtest.py'
--- testtools/runtest.py 2010-10-18 12:41:41 +0000
+++ testtools/runtest.py 2010-11-27 10:55:33 +0000
@@ -1,8 +1,9 @@
-# Copyright (c) 2009 Jonathan M. Lange. See LICENSE for details.
+# Copyright (c) 2009-2010 Jonathan M. Lange. See LICENSE for details.
"""Individual test case execution."""
__all__ = [
+ 'MultipleExceptions',
'RunTest',
]
@@ -11,6 +12,13 @@
from testtools.testresult import ExtendedToOriginalDecorator
+class MultipleExceptions(Exception):
+ """Represents many exceptions raised from some operation.
+
+ :ivar args: The sys.exc_info() tuples for each exception.
+ """
+
+
class RunTest(object):
"""An object to run a test.
@@ -107,7 +115,7 @@
if self.exception_caught == self._run_user(self.case._run_setup,
self.result):
# Don't run the test method if we failed getting here.
- e = self.case._runCleanups(self.result)
+ e = self._run_cleanups(self.result)
if e is not None:
self._exceptions.append(e)
return
@@ -125,7 +133,7 @@
failed = True
finally:
try:
- e = self._run_user(self.case._runCleanups, self.result)
+ e = self._run_user(self._run_cleanups, self.result)
if e is not None:
self._exceptions.append(e)
failed = True
@@ -146,6 +154,35 @@
except:
return self._got_user_exception(sys.exc_info())
+ def _run_cleanups(self, result):
+ """Run the cleanups that have been added with addCleanup.
+
+ See the docstring for addCleanup for more information.
+
+ :return: None if all cleanups ran without error, the most recently
+ raised exception from the cleanups otherwise.
+ """
+ last_exception = None
+ while self.case._cleanups:
+ function, arguments, keywordArguments = self.case._cleanups.pop()
+ try:
+ function(*arguments, **keywordArguments)
+ except KeyboardInterrupt:
+ raise
+ except:
+ exceptions = [sys.exc_info()]
+ while exceptions:
+ try:
+ exc_info = exceptions.pop()
+ if exc_info[0] is MultipleExceptions:
+ exceptions.extend(exc_info[1].args)
+ continue
+ self.case._report_traceback(exc_info)
+ last_exception = exc_info[1]
+ finally:
+ del exc_info
+ return last_exception
+
def _got_user_exception(self, exc_info, tb_label='traceback'):
"""Called when user code raises an exception.
=== modified file 'testtools/testcase.py'
--- testtools/testcase.py 2010-10-31 20:45:29 +0000
+++ testtools/testcase.py 2010-11-27 10:55:33 +0000
@@ -5,7 +5,6 @@
__metaclass__ = type
__all__ = [
'clone_test_with_new_id',
- 'MultipleExceptions',
'run_test_with',
'skip',
'skipIf',
@@ -92,13 +91,6 @@
return decorator
-class MultipleExceptions(Exception):
- """Represents many exceptions raised from some operation.
-
- :ivar args: The sys.exc_info() tuples for each exception.
- """
-
-
class TestCase(unittest.TestCase):
"""Extensions to the basic TestCase.
@@ -224,35 +216,6 @@
className = ', '.join(klass.__name__ for klass in classOrIterable)
return className
- def _runCleanups(self, result):
- """Run the cleanups that have been added with addCleanup.
-
- See the docstring for addCleanup for more information.
-
- :return: None if all cleanups ran without error, the most recently
- raised exception from the cleanups otherwise.
- """
- last_exception = None
- while self._cleanups:
- function, arguments, keywordArguments = self._cleanups.pop()
- try:
- function(*arguments, **keywordArguments)
- except KeyboardInterrupt:
- raise
- except:
- exceptions = [sys.exc_info()]
- while exceptions:
- try:
- exc_info = exceptions.pop()
- if exc_info[0] is MultipleExceptions:
- exceptions.extend(exc_info[1].args)
- continue
- self._report_traceback(exc_info)
- last_exception = exc_info[1]
- finally:
- del exc_info
- return last_exception
-
def addCleanup(self, function, *arguments, **keywordArguments):
"""Add a cleanup function to be called after tearDown.
Follow ups