testtools-dev team mailing list archive
-
testtools-dev team
-
Mailing list archive
-
Message #00278
[Bug 675327] [NEW] Raises/MatchesException regressions
Public bug reported:
The new Matcher introduced in place of assertRaises in r129 has several
different problems across Python versions.
# Python 3
## `raise a, b, c` used in Raises.match is no longer valid syntax, the traceback lives on the exception so unlike on Python 2 just `raise b` and it does the right thing.
## Exception classes get plain names, so the "exceptions." prefix used in tests results in failures.
# Python 2.4
## KeyboardError and SystemExit are still Exception subclasses, so the check in Raises.match is incorrect.
## Exceptions are classobj not type, so the check in MatchesException._expected_type is wrong and breaks anything not passing an instance.
# There's an exc_info cycle created in Raises.match which would be nice to avoid.
These are all pretty trivial to fix apart from the reraise problem, the
best suggestion I found searching the web briefly on that was pretty
gross:
if sys.version_info >= (3,0):
exec ("""
def _reraise(cls, val, tb):
raise val
""")
else:
exec ("""
def _reraise(cls, val, tb):
raise cls, val, tb
""")
<http://www.voidspace.org.uk/python/articles/porting-mock-to-
python-3.shtml>
** Affects: testtools
Importance: Undecided
Status: New
--
Raises/MatchesException regressions
https://bugs.launchpad.net/bugs/675327
You received this bug notification because you are a member of testtools
developers, which is subscribed to testtools.
Status in testtools: New
Bug description:
The new Matcher introduced in place of assertRaises in r129 has several different problems across Python versions.
# Python 3
## `raise a, b, c` used in Raises.match is no longer valid syntax, the traceback lives on the exception so unlike on Python 2 just `raise b` and it does the right thing.
## Exception classes get plain names, so the "exceptions." prefix used in tests results in failures.
# Python 2.4
## KeyboardError and SystemExit are still Exception subclasses, so the check in Raises.match is incorrect.
## Exceptions are classobj not type, so the check in MatchesException._expected_type is wrong and breaks anything not passing an instance.
# There's an exc_info cycle created in Raises.match which would be nice to avoid.
These are all pretty trivial to fix apart from the reraise problem, the best suggestion I found searching the web briefly on that was pretty gross:
if sys.version_info >= (3,0):
exec ("""
def _reraise(cls, val, tb):
raise val
""")
else:
exec ("""
def _reraise(cls, val, tb):
raise cls, val, tb
""")
<http://www.voidspace.org.uk/python/articles/porting-mock-to-python-3.shtml>
Follow ups
References