[Pytest-commit] Issue #767: pytest.raises() doesn't always return Exception instance in py26 (pytest-dev/pytest)
Eric Siegerman
issues-reply at bitbucket.org
Fri Jun 12 21:18:46 CEST 2015
New issue 767: pytest.raises() doesn't always return Exception instance in py26
https://bitbucket.org/pytest-dev/pytest/issue/767/pytestraises-doesnt-always-return
Eric Siegerman:
Typically, the ExceptionInfo.value returned by _pytest.raises()_ (when the exception is indeed raised) is an Exception instance. But under certain conditions, it isn't. It looks as though it contains the Exception's _.args_, rather than the Exception itself. This happens when:
* Python is 2.6 (I've tested with 2.6.6 and 2.6.9), and
* The exception is one of Python's internal ones (I've tested with ZeroDivisionError, KeyError, and IOError; not sure whether this applies to others)
* The exception was raised by the interpreter -- if I explicitly `raise KeyError("msg")`, for example, the test passes
The attached tests demonstrate the problem -- and the more useful behaviour when you use vanilla _try/except_ instead of _pytest.raises()_. Under Python 2.6, the three _pytest.raises()_ cases fail; under Python 2.7 and 3.4, they pass. (The _try/except_ tests pass under all three Python versions.)
More information about the pytest-commit
mailing list