Skip to content
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

[Bug] pytest.raises is passing failing tests when using the 'message' parameter #3350

Closed
gcardozo123 opened this issue Mar 28, 2018 · 3 comments
Labels
type: bug problem that needs to be addressed

Comments

@gcardozo123
Copy link

Platform: Windows 10 64-bit
Pytest Version: 3.5.0

The test bellow passes, but it should fail and print a message saying that it was expecting expected message but got some other message.

import pytest

def test():
	with pytest.raises(ZeroDivisionError, message='expected message'):
		raise ZeroDivisionError('some other message')
@pytestbot
Copy link
Contributor

GitMate.io thinks possibly related issues are #3245 (py.test on pytest fails when not limiting to the testing folder), #3048 (Pytest fails on marking of input parameter if it is a method of a class), #2798 (pytest is leaking frames of tests that fail), #1045 (pytest-warnings fails tests since 2.8), and #1591 (pytest-xdist fails when running same tests several times).

@The-Compiler
Copy link
Member

You probably want match='expected message'. From the documentation:

  • message – if specified, provides a custom failure message if the exception is not raised
  • match – if specified, asserts that the exception matches a text or regex

@pytestbot pytestbot added the type: bug problem that needs to be addressed label Mar 28, 2018
@gcardozo123
Copy link
Author

@The-Compiler thanks, my bad!

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

3 participants