Remove explicit kwargs handling from raises, warns and ParameterSet.param
This commit is contained in:
@@ -10,7 +10,6 @@ in case of warnings which need to format their messages.
|
||||
"""
|
||||
from _pytest.warning_types import PytestDeprecationWarning
|
||||
from _pytest.warning_types import RemovedInPytest4Warning
|
||||
from _pytest.warning_types import UnformattedWarning
|
||||
|
||||
YIELD_TESTS = "yield tests were removed in pytest 4.0 - {name} will be ignored"
|
||||
|
||||
@@ -73,15 +72,3 @@ PYTEST_LOGWARNING = PytestDeprecationWarning(
|
||||
"pytest_logwarning is deprecated, no longer being called, and will be removed soon\n"
|
||||
"please use pytest_warning_captured instead"
|
||||
)
|
||||
|
||||
PYTEST_WARNS_UNKNOWN_KWARGS = UnformattedWarning(
|
||||
PytestDeprecationWarning,
|
||||
"pytest.warns() got unexpected keyword arguments: {args!r}.\n"
|
||||
"This will be an error in future versions.",
|
||||
)
|
||||
|
||||
PYTEST_PARAM_UNKNOWN_KWARGS = UnformattedWarning(
|
||||
PytestDeprecationWarning,
|
||||
"pytest.param() got unexpected keyword arguments: {args!r}.\n"
|
||||
"This will be an error in future versions.",
|
||||
)
|
||||
|
||||
@@ -9,7 +9,6 @@ import attr
|
||||
from ..compat import ascii_escaped
|
||||
from ..compat import getfslineno
|
||||
from ..compat import NOTSET
|
||||
from _pytest.deprecated import PYTEST_PARAM_UNKNOWN_KWARGS
|
||||
from _pytest.outcomes import fail
|
||||
from _pytest.warning_types import PytestUnknownMarkWarning
|
||||
|
||||
@@ -61,26 +60,19 @@ def get_empty_parameterset_mark(config, argnames, func):
|
||||
|
||||
class ParameterSet(namedtuple("ParameterSet", "values, marks, id")):
|
||||
@classmethod
|
||||
def param(cls, *values, **kwargs):
|
||||
marks = kwargs.pop("marks", ())
|
||||
def param(cls, *values, marks=(), id=None):
|
||||
if isinstance(marks, MarkDecorator):
|
||||
marks = (marks,)
|
||||
else:
|
||||
assert isinstance(marks, (tuple, list, set))
|
||||
|
||||
id_ = kwargs.pop("id", None)
|
||||
if id_ is not None:
|
||||
if not isinstance(id_, str):
|
||||
if id is not None:
|
||||
if not isinstance(id, str):
|
||||
raise TypeError(
|
||||
"Expected id to be a string, got {}: {!r}".format(type(id_), id_)
|
||||
"Expected id to be a string, got {}: {!r}".format(type(id), id)
|
||||
)
|
||||
id_ = ascii_escaped(id_)
|
||||
|
||||
if kwargs:
|
||||
warnings.warn(
|
||||
PYTEST_PARAM_UNKNOWN_KWARGS.format(args=sorted(kwargs)), stacklevel=3
|
||||
)
|
||||
return cls(values, marks, id_)
|
||||
id = ascii_escaped(id)
|
||||
return cls(values, marks, id)
|
||||
|
||||
@classmethod
|
||||
def extract_from(cls, parameterset, force_tuple=False):
|
||||
|
||||
@@ -523,7 +523,7 @@ def _is_numpy_array(obj):
|
||||
# builtin pytest.raises helper
|
||||
|
||||
|
||||
def raises(expected_exception, *args, **kwargs):
|
||||
def raises(expected_exception, *args, match=None, **kwargs):
|
||||
r"""
|
||||
Assert that a code block/function call raises ``expected_exception``
|
||||
or raise a failure exception otherwise.
|
||||
@@ -649,16 +649,14 @@ def raises(expected_exception, *args, **kwargs):
|
||||
raise TypeError(msg % type(exc))
|
||||
|
||||
message = "DID NOT RAISE {}".format(expected_exception)
|
||||
match_expr = None
|
||||
|
||||
if not args:
|
||||
if "match" in kwargs:
|
||||
match_expr = kwargs.pop("match")
|
||||
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_expr)
|
||||
return RaisesContext(expected_exception, message, match)
|
||||
else:
|
||||
func = args[0]
|
||||
if not callable(func):
|
||||
|
||||
@@ -3,7 +3,6 @@ import inspect
|
||||
import re
|
||||
import warnings
|
||||
|
||||
from _pytest.deprecated import PYTEST_WARNS_UNKNOWN_KWARGS
|
||||
from _pytest.fixtures import yield_fixture
|
||||
from _pytest.outcomes import fail
|
||||
|
||||
@@ -43,7 +42,7 @@ def deprecated_call(func=None, *args, **kwargs):
|
||||
return warns((DeprecationWarning, PendingDeprecationWarning), *args, **kwargs)
|
||||
|
||||
|
||||
def warns(expected_warning, *args, **kwargs):
|
||||
def warns(expected_warning, *args, match=None, **kwargs):
|
||||
r"""Assert that code raises a particular class of warning.
|
||||
|
||||
Specifically, the parameter ``expected_warning`` can be a warning class or
|
||||
@@ -77,12 +76,12 @@ def warns(expected_warning, *args, **kwargs):
|
||||
"""
|
||||
__tracebackhide__ = True
|
||||
if not args:
|
||||
match_expr = kwargs.pop("match", None)
|
||||
if kwargs:
|
||||
warnings.warn(
|
||||
PYTEST_WARNS_UNKNOWN_KWARGS.format(args=sorted(kwargs)), stacklevel=2
|
||||
)
|
||||
return WarningsChecker(expected_warning, match_expr=match_expr)
|
||||
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:
|
||||
func = args[0]
|
||||
if not callable(func):
|
||||
|
||||
Reference in New Issue
Block a user