-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
pytest.raises makes it impossible to check error messages and it should NOT accept parent classes by default #258
Comments
Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt): your test is wrong a pytest.fail raises a pytest.fail.Exception, not an assertionerror |
Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt): and the other test is expecting time travel |
Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt): all your tests on pytest.raises make wrong assumptions |
Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt): the only problem i discovered is that pytest.fail.Exception has a empty string in the message attribute, the rest os pretty much correct |
Original comment by Ronny Pfannschmidt (BitBucket: RonnyPfannschmidt, GitHub: RonnyPfannschmidt): i just pushed a bugfix about exception attributes, other than that there is nothing wrong with pytest.raises we might want to add a raises.regex that in addition to the exception takes a Regex |
I understand that you closed the issue but I fell into the same semantics trap. I believe this justifies a proper answer... this is what I tried: def test_pytest_raises_message():
with pytest.raises(Exception, message='expected message'):
raise Exception('this should FAIL')
pytest.fail("Did not FAIL!") this is how its done (notice the "match" part) def test_pytest_raises_message():
with pytest.raises(Exception, match='expected message'):
raise Exception('this should FAIL')
pytest.fail("Did not FAIL!") |
@markfink You probably want
|
@The-Compiler i believe we should fail with unexpected parameters to raises edit yikes i did misread, sorry |
Definitely, opened #3348 for that. |
Originally reported by: Peter Hillerström (BitBucket: peterhil, GitHub: peterhil)
Pytest.raises code seems to be too complicated.
Find attached a code for simple 'raises' -context manager and
three simple tests for both. See the failures in the test run at the end.
Example test run:
The text was updated successfully, but these errors were encountered: