-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Misleading pytest exception description #475
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
Comments
Original comment by Floris Bruynooghe (BitBucket: flub, GitHub: flub): So it seems that python 3 only allows subclasses from BaseException, we could enforece this in raises? This is likely too strict though for backwards compatibility so maybe simply checking it is a class or tuple as suggested is better. |
Original comment by Jurko Gospodnetić (BitBucket: jurko, GitHub: jurko): In both py2 & py3 On py3 it would also be nice to check that the passed classes are subclasses of BaseException, but that's a separate and I guess an unrelated issue. Best regards, |
Originally reported by: Jurko Gospodnetić (BitBucket: jurko, GitHub: jurko)
Today, while mentoring a new colleague in Python and TDD, she ran into a pytest exception description which confused her, and with her being a novice programmer, was completely out of her league to debug.
Here is a reduced script demonstrating the issue:
The given test code has a bug -
pytest.raises()
should be givenException
class as its parameter and not an integerInvalidLabSize
. However, pytestreports this in a most misleading way:
First, it points to an incorrect code line - it points to the code line
Lab(0)
as causing the error when in fact it was the line before that caused it.Second, it complains about some 'argument number 2' to some
issubclass()
call having to be a class or a tuple of classes, when neither the user code nor anything displayed in the given exception stack information contains anyissubclass()
calls.It should in fact say that the first parameter to
pyteset.raises()
should be a class or a tuple of classes.As a side-note, I tried rewriting the test using the older pytest.raises() calling style (without using a
with
context manager):and this reports much more relevant information when run under Python 3.x:
Running it under Python 2.x on the other hand displays a bit less but still misleading information:
It says that an Exception got raised when it should in fact say that an Exception got raised but an integer -1 was expected.
Hope this helps.
Best regards,
Jurko Gospodnetić
The text was updated successfully, but these errors were encountered: