Skip to content

Commit 4c6ded7

Browse files
committed
docs fixes after removing the raises_group alias.
1 parent d37e6d6 commit 4c6ded7

File tree

3 files changed

+11
-16
lines changed

3 files changed

+11
-16
lines changed

doc/en/how-to/assert.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,14 @@ Notes:
148148
Assertions about expected exception groups
149149
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150150

151-
When expecting a :exc:`BaseExceptionGroup` or :exc:`ExceptionGroup` you can use :class:`pytest.RaisesGroup`, also available as :class:`pytest.raises_group <pytest.RaisesGroup>`:
151+
When expecting a :exc:`BaseExceptionGroup` or :exc:`ExceptionGroup` you can use :class:`pytest.RaisesGroup`:
152152

153153
.. code-block:: python
154154
155155
def test_exception_in_group():
156-
with pytest.raises_group(ValueError):
156+
with pytest.RaisesGroup(ValueError):
157157
raise ExceptionGroup("group msg", [ValueError("value msg")])
158-
with pytest.raises_group(ValueError, TypeError):
158+
with pytest.RaisesGroup(ValueError, TypeError):
159159
raise ExceptionGroup("msg", [ValueError("foo"), TypeError("bar")])
160160
161161
@@ -164,9 +164,9 @@ It accepts a ``match`` parameter, that checks against the group message, and a `
164164
.. code-block:: python
165165
166166
def test_raisesgroup_match_and_check():
167-
with pytest.raises_group(BaseException, match="my group msg"):
167+
with pytest.RaisesGroup(BaseException, match="my group msg"):
168168
raise BaseExceptionGroup("my group msg", [KeyboardInterrupt()])
169-
with pytest.raises_group(
169+
with pytest.RaisesGroup(
170170
Exception, check=lambda eg: isinstance(eg.__cause__, ValueError)
171171
):
172172
raise ExceptionGroup("", [TypeError()]) from ValueError()
@@ -176,19 +176,19 @@ It is strict about structure and unwrapped exceptions, unlike :ref:`except* <exc
176176
.. code-block:: python
177177
178178
def test_structure():
179-
with pytest.raises_group(pytest.raises_group(ValueError)):
179+
with pytest.RaisesGroup(pytest.RaisesGroup(ValueError)):
180180
raise ExceptionGroup("", (ExceptionGroup("", (ValueError(),)),))
181-
with pytest.raises_group(ValueError, flatten_subgroups=True):
181+
with pytest.RaisesGroup(ValueError, flatten_subgroups=True):
182182
raise ExceptionGroup("1st group", [ExceptionGroup("2nd group", [ValueError()])])
183-
with pytest.raises_group(ValueError, allow_unwrapped=True):
183+
with pytest.RaisesGroup(ValueError, allow_unwrapped=True):
184184
raise ValueError
185185
186186
To specify more details about the contained exception you can use :class:`pytest.RaisesExc`
187187

188188
.. code-block:: python
189189
190190
def test_raises_exc():
191-
with pytest.raises_group(pytest.RaisesExc(ValueError, match="foo")):
191+
with pytest.RaisesGroup(pytest.RaisesExc(ValueError, match="foo")):
192192
raise ExceptionGroup("", (ValueError("foo")))
193193
194194
They both supply a method :meth:`pytest.RaisesGroup.matches` :meth:`pytest.RaisesExc.matches` if you want to do matching outside of using it as a contextmanager. This can be helpful when checking ``.__context__`` or ``.__cause__``.
@@ -231,7 +231,7 @@ Check the documentation on :class:`pytest.RaisesGroup` and :class:`pytest.Raises
231231
232232
233233
There is no good way of using :func:`excinfo.group_contains() <pytest.ExceptionInfo.group_contains>` to ensure you're not getting *any* other exceptions than the one you expected.
234-
You should instead use :class:`pytest.raises_group <pytest.RaisesGroup>`, see :ref:`assert-matching-exception-groups`.
234+
You should instead use :class:`pytest.RaisesGroup`, see :ref:`assert-matching-exception-groups`.
235235

236236
You can also use the :func:`excinfo.group_contains() <pytest.ExceptionInfo.group_contains>`
237237
method to test for exceptions returned as part of an :class:`ExceptionGroup`:

src/_pytest/_code/code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ def group_contains(
840840
This helper makes it easy to check for the presence of specific exceptions,
841841
but it is very bad for checking that the group does *not* contain
842842
*any other exceptions*.
843-
You should instead consider using :class:`pytest.raises_group <pytest.RaisesGroup>`
843+
You should instead consider using :class:`pytest.RaisesGroup`
844844
845845
"""
846846
msg = "Captured exception is not an instance of `BaseExceptionGroup`"

src/_pytest/python_api.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
from _pytest.raises_group import RaisesExc
2323

2424

25-
if sys.version_info < (3, 11):
26-
pass
27-
2825
if TYPE_CHECKING:
2926
from numpy import ndarray
3027

@@ -771,8 +768,6 @@ def _as_numpy_array(obj: object) -> ndarray | None:
771768
Return an ndarray if the given object is implicitly convertible to ndarray,
772769
and numpy is already imported, otherwise None.
773770
"""
774-
import sys
775-
776771
np: Any = sys.modules.get("numpy")
777772
if np is not None:
778773
# avoid infinite recursion on numpy scalars, which have __array__

0 commit comments

Comments
 (0)