← Back to team overview

testtools-dev team mailing list archive

[Bug 675327] Re: Raises/MatchesException regressions

 

** Changed in: testtools
       Status: Fix Committed => Fix Released

-- 
You received this bug notification because you are a member of testtools
developers, which is subscribed to testtools.
https://bugs.launchpad.net/bugs/675327

Title:
  Raises/MatchesException regressions

Status in testtools:
  Fix Released

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>





References