@@ -62,9 +62,9 @@ def deprecated_call(func: Callable[P, T], *args: P.args, **kwargs: P.kwargs) ->
6262def deprecated_call (
6363 func : Callable [..., Any ] | None = None , * args : Any , ** kwargs : Any
6464) -> WarningsRecorder | Any :
65- """Assert that a code block produces a ``DeprecationWarning`` or ``PendingDeprecationWarning`` or ``FutureWarning``.
65+ """Assert that code produces a ``DeprecationWarning`` or ``PendingDeprecationWarning`` or ``FutureWarning``.
6666
67- This function is used as a context manager::
67+ This function can be used as a context manager::
6868
6969 >>> import warnings
7070 >>> def api_call_v2():
@@ -77,14 +77,19 @@ def deprecated_call(
7777 >>> with pytest.deprecated_call(match="^use v3 of this api$") as warning_messages:
7878 ... assert api_call_v2() == 200
7979
80- You may use the keyword argument ``match`` to assert
80+ It can also be used by passing a function and ``*args`` and ``**kwargs``,
81+ in which case it will ensure calling ``func(*args, **kwargs)`` produces one of
82+ the warnings types above. The return value is the return value of the function.
83+
84+ In the context manager form you may use the keyword argument ``match`` to assert
8185 that the warning matches a text or regex.
8286
83- This helper produces a list of :class:`warnings.WarningMessage` objects, one for
84- each warning emitted (regardless of whether it is an ``expected_warning`` or not).
87+ The context manager produces a list of :class:`warnings.WarningMessage` objects,
88+ one for each warning emitted
89+ (regardless of whether it is an ``expected_warning`` or not).
8590 """
8691 __tracebackhide__ = True
87- # potential QoL: allow `with deprecated_call:` - i.e. no parens
92+ # Potential QoL: allow `with deprecated_call:` - i.e. no parens
8893 dep_warnings = (DeprecationWarning , PendingDeprecationWarning , FutureWarning )
8994 if func is None :
9095 return warns (dep_warnings , * args , ** kwargs )
@@ -118,7 +123,7 @@ def warns(
118123 * args : Any ,
119124 ** kwargs : Any ,
120125) -> WarningsChecker | Any :
121- r"""Assert that a code block raises a particular class of warning.
126+ r"""Assert that code raises a particular class of warning.
122127
123128 Specifically, the parameter ``expected_warning`` can be a warning class or tuple
124129 of warning classes, and the code inside the ``with`` block must issue at least one
@@ -128,13 +133,13 @@ def warns(
128133 each warning emitted (regardless of whether it is an ``expected_warning`` or not).
129134 Since pytest 8.0, unmatched warnings are also re-emitted when the context closes.
130135
131- Use this function as a context manager::
136+ This function can be used as a context manager::
132137
133138 >>> import pytest
134139 >>> with pytest.warns(RuntimeWarning):
135140 ... warnings.warn("my warning", RuntimeWarning)
136141
137- You can use the keyword argument ``match`` to assert
142+ In the context manager form you may use the keyword argument ``match`` to assert
138143 that the warning matches a text or regex::
139144
140145 >>> with pytest.warns(UserWarning, match='must be 0 or None'):
0 commit comments