From dfe54cd82f55f17f3c9e6e078325f306a046b93b Mon Sep 17 00:00:00 2001 From: Bruno Oliveira Date: Wed, 3 Jul 2019 13:57:28 -0300 Subject: [PATCH] Let context-managers for raises and warns handle unknown keyword arguments As suggested during review --- src/_pytest/python_api.py | 9 +++------ src/_pytest/recwarn.py | 7 +------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/_pytest/python_api.py b/src/_pytest/python_api.py index 3266188a1..3d52bbbcf 100644 --- a/src/_pytest/python_api.py +++ b/src/_pytest/python_api.py @@ -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): diff --git a/src/_pytest/recwarn.py b/src/_pytest/recwarn.py index 8a1cad4a1..3ab83d1e3 100644 --- a/src/_pytest/recwarn.py +++ b/src/_pytest/recwarn.py @@ -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):