Skip to content

pytest.raises() doesn't always return Exception instance in py26 #767

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pytestbot opened this issue Jun 12, 2015 · 1 comment
Closed

pytest.raises() doesn't always return Exception instance in py26 #767

pytestbot opened this issue Jun 12, 2015 · 1 comment
Labels
type: bug problem that needs to be addressed

Comments

@pytestbot
Copy link
Contributor

Originally reported by: Eric Siegerman (BitBucket: eks, GitHub: eks)


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 all of the following are true:

  • Python is 2.6 (I've tested with 2.6.6 and 2.6.9)
  • 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.)


@nicoddemus
Copy link
Member

@eks, FYI: #788. Thanks for the report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug problem that needs to be addressed
Projects
None yet
Development

No branches or pull requests

2 participants