texttest / capturemock

2 stars 2 forks source link

exception inheritance no longer works in Python 3 #4

Open gjb1002 opened 5 years ago

gjb1002 commented 5 years ago

The main reason is that Python 3 does not allow catching exceptions that don't inherit from BaseException. In Python 2 you could catch anything at all.

This caused the failure of TextTest self-tests NoSuchUser and NoSuchSender. Have fixed these for now by hacking in the mock file, should be reverted when this is fixed.

gjb1002 commented 5 years ago

In total responsible for 8 failing TextTest self-tests, including 3 that hang under ec2cloud.

gjb1002 commented 5 years ago

Basic problem is the situation when you have two levels of exception in the intercepted module.

class MyBaseException(RuntimeError):
    pass

class MyDerivedException(MyBaseException):
    pass

Capturemock represents this as

<-PYT:raise MyDerivedException(MyBaseException, RuntimeError)("error msg") but this leads to a multiple inheritance situation and crucially MyBaseException ends up not being derived from RuntimeError, meaning if the code catches it failure will result.

Perhaps it needs to say

<-PYT:raise MyDerivedException(MyBaseException(RuntimeError))("error msg")

but my attempts to make that work with name handlers etc didn't work so well.

gjb1002 commented 5 years ago

All failing self-tests have either been worked around or disabled though (not all were this issue in the end, in some cases exceptions had just been renamed).

In any case this is no longer critical there.