Let context-managers for raises and warns handle unknown keyword arguments

As suggested during review
This commit is contained in:
Bruno Oliveira 2019-07-03 13:57:28 -03:00
parent 0ed7aa2db6
commit dfe54cd82f
2 changed files with 4 additions and 12 deletions

View File

@ -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):

View File

@ -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):