{"id":"26c59368930b4c34","repo":"pytest-dev/pytest","slug":"you-cannot-specify-multiple-exceptions-with-allow","errorCode":null,"errorMessage":"You cannot specify multiple exceptions with `allow_unwrapped=True.` If you want to match one of multiple possible exceptions you should use a `RaisesExc`. E.g. `RaisesExc(check=lambda e: isinstance(e, (...)))`","messagePattern":"You cannot specify multiple exceptions with `allow_unwrapped=True\\.` If you want to match one of multiple possible exceptions you should use a `RaisesExc`\\. E\\.g\\. `RaisesExc\\(check=lambda e: isinstance\\(e, \\(\\.\\.\\.\\)\\)\\)`","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/_pytest/raises.py","lineNumber":971,"sourceCode":"            Callable[[BaseExceptionGroup[BaseExcT_1]], bool]\n            | Callable[[ExceptionGroup[ExcT_1]], bool]\n            | None\n        ) = None,\n    ):\n        # The type hint on the `self` and `check` parameters uses different formats\n        # that are *very* hard to reconcile while adhering to the overloads, so we cast\n        # it to avoid an error when passing it to super().__init__\n        check = cast(\n            \"Callable[[BaseExceptionGroup[ExcT_1|BaseExcT_1|BaseExceptionGroup[BaseExcT_2]]], bool]\",\n            check,\n        )\n        super().__init__(match=match, check=check)\n        self.allow_unwrapped = allow_unwrapped\n        self.flatten_subgroups: bool = flatten_subgroups\n        self.is_baseexception = False\n\n        if allow_unwrapped and other_exceptions:\n            raise ValueError(\n                \"You cannot specify multiple exceptions with `allow_unwrapped=True.`\"\n                \" If you want to match one of multiple possible exceptions you should\"\n                \" use a `RaisesExc`.\"\n                \" E.g. `RaisesExc(check=lambda e: isinstance(e, (...)))`\",\n            )\n        if allow_unwrapped and isinstance(expected_exception, RaisesGroup):\n            raise ValueError(\n                \"`allow_unwrapped=True` has no effect when expecting a `RaisesGroup`.\"\n                \" You might want it in the expected `RaisesGroup`, or\"\n                \" `flatten_subgroups=True` if you don't care about the structure.\",\n            )\n        if allow_unwrapped and (match is not None or check is not None):\n            raise ValueError(\n                \"`allow_unwrapped=True` bypasses the `match` and `check` parameters\"\n                \" if the exception is unwrapped. If you intended to match/check the\"\n                \" exception you should use a `RaisesExc` object. If you want to match/check\"\n                \" the exceptiongroup when the exception *is* wrapped you need to\"\n                \" do e.g. `if isinstance(exc.value, ExceptionGroup):\"","sourceCodeStart":953,"sourceCodeEnd":989,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/raises.py#L953-L989","documentation":"allow_unwrapped only makes sense for a single expected exception; specifying multiple exceptions alongside allow_unwrapped=True is ambiguous because unwrapping applies to exactly one exception. Use RaisesExc with a check for 'one of several'.","triggerScenarios":"Calling RaisesGroup(ValueError, TypeError, allow_unwrapped=True) — two or more positional exceptions with allow_unwrapped. Hits raises.py:971.","commonSituations":"Developer wants to match one of several possible exceptions that may or may not be wrapped in a group; misunderstanding that allow_unwrapped is singular.","solutions":["Use RaisesExc(check=lambda e: isinstance(e, (ValueError, TypeError))) to express 'one of several', optionally inside a RaisesGroup with allow_unwrapped.","Drop allow_unwrapped if you genuinely expect a group containing multiple exceptions.","Split into separate RaisesGroup blocks per exception type if the structure differs."],"exampleFix":"// before\nwith RaisesGroup(ValueError, TypeError, allow_unwrapped=True):\n    raise ValueError()\n// after\nwith RaisesGroup(RaisesExc(check=lambda e: isinstance(e, (ValueError, TypeError))), allow_unwrapped=True):\n    raise ValueError()","handlingStrategy":"validation","validationCode":"if allow_unwrapped and len(expected) > 1:\n    raise ValueError('use RaisesExc(check=...) for one-of-several with allow_unwrapped')\nRaisesGroup(*expected, allow_unwrapped=allow_unwrapped)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["allow_unwrapped is singular — pair it with exactly one expected exception.","For 'one of several', wrap a RaisesExc(check=isinstance) inside the RaisesGroup.","Review the RaisesGroup docstring examples before combining flags."],"tags":["pytest","raises-group","validation"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}