being much stricter about the structure by default. By using ``allow_unwrapped=True`` and ``flatten_subgroups=True`` you can match :ref:`except* ` fully when expecting a single exception. :param args: Any number of exception types, :class:`RaisesGroup` or :class:`RaisesExc` to specify the exceptions contained in this exception. All specified exceptions must be present in the raised group, *and no others*. If you expect a variable number of exceptions you need to use :func:`pytest.raises(ExceptionGroup) ` and manually check the contained exceptions. Consider making use of :meth:`RaisesExc.matches`. It does not care about the order of the exceptions, so ``RaisesGroup(ValueError, TypeError)`` is equivalent to ``RaisesGroup(TypeError, ValueError)``. :kwparam str | re.Pattern[str] | None match: If specified, a string containing a regular expression, or a regular expression object, that is tested against the string representation of the exception group and its :pep:`678` `__notes__` using :func:`re.search`. To match a literal string that may contain :ref:`special characters `, the pattern can first be escaped with :func:`re.escape`. Note that " (5 subgroups)" will be stripped from the ``repr`` before matching. :kwparam Callable[[E], bool] check: If specified, a callable that will be called with the group as a parameter after successfully matching the expected exceptions. If it returns ``True`` it will be considered a match, if not it will be considered a failed match. :kwparam bool allow_unwrapped: If expecting a single exception or :class:`RaisesExc` it will match even if the exception is not inside an exceptiongroup. Using this together with ``match``, ``check`` or expecting multiple exceptions will raise an error. :kwparam bool flatten_subgroups: "flatten" any groups inside the raised exception group, extracting all exceptions inside any nested groups, before matching. Without this it expects you to fully specify the nesting structure by passing :class:`RaisesGroup` as expected parameter. Examples:: with RaisesGroup(ValueError): raise ExceptionGroup("", (ValueError(),)) # match with RaisesGroup( ValueError, ValueError, RaisesExc(TypeError, match="^expected int$"), match="^my group$", ): raise ExceptionGroup( "my group", [ ValueError(), TypeError("expected int"), ValueError(), ], ) # check with RaisesGroup( KeyboardInterrupt, match="^hello$", check=lambda x: isinstance(x.__cause__, ValueError), ): raise BaseExceptionGroup("hello", [KeyboardInterrupt()]) from ValueError # nested groups with RaisesGroup(RaisesGroup(ValueError)): raise ExceptionGroup("", (ExceptionGroup("", (ValueError(),)),)) # flatten_subgroups with RaisesGroup(ValueError, flatten_subgroups=True): raise ExceptionGroup("", (ExceptionGroup("", (ValueError(),)),)) # allow_unwrapped with RaisesGroup(ValueError, allow_unwrapped=True): raise ValueError :meth:`RaisesGroup.matches` can also be used directly to check a standalone exception group. The matching algorithm is greedy, which means cases such as this may fail:: with RaisesGroup(ValueError, RaisesExc(ValueError, match="hello")): raise ExceptionGroup("", (ValueError("hello"), ValueError("goodbye"))) even though it generally does not care about the order of the exceptions in the group. To avoid the above you should specify the first :exc:`ValueError` with a :class:`RaisesExc` as well. .. note:: When raised exceptions don't match the expected ones, you'll get a detailed error message explaining why. This includes ``repr(check)`` if set, which in Python can be overly verbose, showing memory locations etc etc. If installed and imported (in e.g. ``conftest.py``), the ``hypothesis`` library will monkeypatch this output to provide shorter & more readable repr's. Ú