You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/en/how-to/assert.rst
+10-10Lines changed: 10 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -148,14 +148,14 @@ Notes:
148
148
Assertions about expected exception groups
149
149
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
150
150
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`:
with pytest.raises_group(ValueError, allow_unwrapped=True):
183
+
with pytest.RaisesGroup(ValueError, allow_unwrapped=True):
184
184
raiseValueError
185
185
186
186
To specify more details about the contained exception you can use :class:`pytest.RaisesExc`
187
187
188
188
.. code-block:: python
189
189
190
190
deftest_raises_exc():
191
-
with pytest.raises_group(pytest.RaisesExc(ValueError, match="foo")):
191
+
with pytest.RaisesGroup(pytest.RaisesExc(ValueError, match="foo")):
192
192
raise ExceptionGroup("", (ValueError("foo")))
193
193
194
194
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
231
231
232
232
233
233
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`.
235
235
236
236
You can also use the :func:`excinfo.group_contains() <pytest.ExceptionInfo.group_contains>`
237
237
method to test for exceptions returned as part of an :class:`ExceptionGroup`:
0 commit comments