Skip to content

Commit

Permalink
Let context-managers for raises and warns handle unknown keyword argu…
Browse files Browse the repository at this point in the history
…ments

As suggested during review
  • Loading branch information
nicoddemus committed Jul 3, 2019
1 parent 0ed7aa2 commit dfe54cd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
9 changes: 3 additions & 6 deletions src/_pytest/python_api.py
Expand Up @@ -651,12 +651,9 @@ def raises(expected_exception, *args, match=None, **kwargs):
message = "DID NOT RAISE {}".format(expected_exception)

if not args:
if kwargs:
msg = "Unexpected keyword arguments passed to pytest.raises: "
msg += ", ".join(sorted(kwargs))
msg += "\nUse context-manager form instead?"
raise TypeError(msg)
return RaisesContext(expected_exception, message, match)
return RaisesContext(
expected_exception, message=message, match_expr=match, **kwargs
)
else:
func = args[0]
if not callable(func):
Expand Down
7 changes: 1 addition & 6 deletions src/_pytest/recwarn.py
Expand Up @@ -76,12 +76,7 @@ def warns(expected_warning, *args, match=None, **kwargs):
"""
__tracebackhide__ = True
if not args:
if kwargs:
msg = "Unexpected keyword arguments passed to pytest.warns: "
msg += ", ".join(sorted(kwargs))
msg += "\nUse context-manager form instead?"
raise TypeError(msg)
return WarningsChecker(expected_warning, match_expr=match)
return WarningsChecker(expected_warning, match_expr=match, **kwargs)
else:
func = args[0]
if not callable(func):
Expand Down

0 comments on commit dfe54cd

Please sign in to comment.