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) message = "DID NOT RAISE {}".format(expected_exception)
if not args: if not args:
if kwargs: return RaisesContext(
msg = "Unexpected keyword arguments passed to pytest.raises: " expected_exception, message=message, match_expr=match, **kwargs
msg += ", ".join(sorted(kwargs)) )
msg += "\nUse context-manager form instead?"
raise TypeError(msg)
return RaisesContext(expected_exception, message, match)
else: else:
func = args[0] func = args[0]
if not callable(func): if not callable(func):

View File

@ -76,12 +76,7 @@ def warns(expected_warning, *args, match=None, **kwargs):
""" """
__tracebackhide__ = True __tracebackhide__ = True
if not args: if not args:
if kwargs: return WarningsChecker(expected_warning, match_expr=match, **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)
else: else:
func = args[0] func = args[0]
if not callable(func): if not callable(func):