New issue 580: OutcomeException should not be a subclass of Exception
https://bitbucket.org/hpk42/pytest/issue/580/outcomeexception-should-not-be-a-subclass

thiefmaster:

Imagine this code:

```
def blackbox(callback, arg):
    # this is assumed to be application code
    try:
        callback(arg)
    except Exception:
        pass


def test_callback():
    def cb(x):
        if not x:
            import pytest
            pytest.fail('foo')

    blackbox(cb, True)
    blackbox(cb, False)
```

The testcase will pass since `except Exception` will catch the `Failed` raised 
by `pytest.fail`. However, I don't think there is *any* valid use-case for 
application code to prevent a testcase failure from propagating to the test 
runner.

A more practical example where this is a major issue is monkeypatching a 
library function to fail when called. For example, one might want to 
monkeypatch `smtplib.SMTP.connect` to fail when code tries to send an email 
unexpectedly - but chances are good that the application is wrapping that code 
in a `try...except Exception` block to prevent an email sending failure from 
breaking things (e.g. because the email is not very important). So now the 
`pytest.fail` called in the monkeypatched method will never propagate since 
it's caught by application code.


_______________________________________________
pytest-commit mailing list
pytest-commit@python.org
https://mail.python.org/mailman/listinfo/pytest-commit

Reply via email to