testtools-dev team mailing list archive
-
testtools-dev team
-
Mailing list archive
-
Message #00009
[Merge] lp:~gz/testtools/catch_string_exceptions_592262 into lp:testtools
Martin [gz] has proposed merging lp:~gz/testtools/catch_string_exceptions_592262 into lp:testtools.
Requested reviews:
testtools developers (testtools-dev)
Related bugs:
#592262 testtools breaks if a string exception is raised
https://bugs.launchpad.net/bugs/592262
Minimal fix to make string exceptions raised by Python 2.4 and Python 2.5 handled by testtools rather than aborting the test run. This is something of an edge case they've long been deprecated, but occasionally get raised by mistake.
--
https://code.launchpad.net/~gz/testtools/catch_string_exceptions_592262/+merge/31313
Your team testtools developers is requested to review the proposed merge of lp:~gz/testtools/catch_string_exceptions_592262 into lp:testtools.
=== modified file 'testtools/compat.py'
--- testtools/compat.py 2010-07-29 14:08:10 +0000
+++ testtools/compat.py 2010-07-29 18:27:45 +0000
@@ -209,7 +209,7 @@
list = []
if evalue is None:
# Is a (deprecated) string exception
- list.append(sclass.decode("ascii", "replace"))
+ list.append(eclass.decode("ascii", "replace"))
elif isinstance(evalue, SyntaxError) and len(evalue.args) > 1:
# Avoid duplicating the special formatting for SyntaxError here,
# instead create a new instance with unicode filename and line
=== modified file 'testtools/runtest.py'
--- testtools/runtest.py 2010-07-29 12:20:37 +0000
+++ testtools/runtest.py 2010-07-29 18:27:45 +0000
@@ -144,9 +144,7 @@
return fn(*args)
except KeyboardInterrupt:
raise
- except Exception:
- # Note that bare exceptions are not caught, so raised strings will
- # escape: but they are deprecated anyway.
+ except:
exc_info = sys.exc_info()
e = exc_info[1]
self.case.onException(exc_info)
=== modified file 'testtools/testcase.py'
--- testtools/testcase.py 2010-06-22 23:24:30 +0000
+++ testtools/testcase.py 2010-07-29 18:27:45 +0000
@@ -89,6 +89,9 @@
(_UnexpectedSuccess, self._report_unexpected_success),
(Exception, self._report_error),
]
+ if sys.version_info < (2, 6):
+ # Catch old-style string exceptions with None as the instance
+ self.exception_handlers.append((type(None), self._report_error))
def __eq__(self, other):
eq = getattr(unittest.TestCase, '__eq__', None)
=== modified file 'testtools/tests/test_testresult.py'
--- testtools/tests/test_testresult.py 2010-07-29 14:06:04 +0000
+++ testtools/tests/test_testresult.py 2010-07-29 18:27:45 +0000
@@ -990,7 +990,6 @@
def test_string_exception(self):
"""Raise a string rather than an exception instance if supported"""
- self.skip('# GZ 2010-05-25: Seems this breaks testtools internals.')
if sys.version_info > (2, 6):
self.skip("No string exceptions in Python 2.6 or later")
elif sys.version_info > (2, 5):
Follow ups