[Pytest-commit] Issue #580: OutcomeException should not be a subclass of Exception (hpk42/pytest)
thiefmaster
issues-reply at bitbucket.org
Thu Sep 4 13:23:26 CEST 2014
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.
More information about the pytest-commit
mailing list