Skip to content

Raise TypeError for with raises(..., match=<non-None falsey value>). #4540

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

Merged
merged 1 commit into from
Dec 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/4538.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Raise ``TypeError`` for ``with raises(..., match=<non-None falsey value>)``.
2 changes: 1 addition & 1 deletion src/_pytest/python_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,6 +716,6 @@ def __exit__(self, *tp):
suppress_exception = issubclass(self.excinfo.type, self.expected_exception)
if sys.version_info[0] == 2 and suppress_exception:
sys.exc_clear()
if self.match_expr and suppress_exception:
if self.match_expr is not None and suppress_exception:
self.excinfo.match(self.match_expr)
return suppress_exception
5 changes: 5 additions & 0 deletions testing/python/raises.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def __call__(self):
except pytest.raises.Exception:
pass

def test_raises_falsey_type_error(self):
with pytest.raises(TypeError):
with pytest.raises(AssertionError, match=0):
raise AssertionError("ohai")

def test_raises_repr_inflight(self):
"""Ensure repr() on an exception info inside a pytest.raises with block works (#4386)"""

Expand Down