{"id":"7b7580126be7ec05","repo":"pytest-dev/pytest","slug":"allow-unwrapped-true-has-no-effect-when-expectin","errorCode":null,"errorMessage":"`allow_unwrapped=True` has no effect when expecting a `RaisesGroup`. You might want it in the expected `RaisesGroup`, or `flatten_subgroups=True` if you don't care about the structure.","messagePattern":"`allow_unwrapped=True` has no effect when expecting a `RaisesGroup`\\. You might want it in the expected `RaisesGroup`, or `flatten_subgroups=True` if you don't care about the structure\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/_pytest/raises.py","lineNumber":978,"sourceCode":"        # 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):\"\n                \" assert RaisesGroup(...).matches(exc.value)` afterwards.\",\n            )\n\n        self.expected_exceptions: tuple[\n            type[BaseExcT_co] | RaisesExc[BaseExcT_co] | RaisesGroup[BaseException], ...\n        ] = tuple(\n            self._parse_excgroup(e, \"a BaseException type, RaisesExc, or RaisesGroup\")","sourceCodeStart":960,"sourceCodeEnd":996,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/raises.py#L960-L996","documentation":"allow_unwrapped=True on a RaisesGroup whose sole expected is itself a RaisesGroup has no effect — the outer group always expects a group, so unwrapping at that level is meaningless. The flag belongs on the inner RaisesGroup, or use flatten_subgroups.","triggerScenarios":"Calling RaisesGroup(RaisesGroup(ValueError), allow_unwrapped=True). Hits raises.py:978.","commonSituations":"Developer nests groups to assert structure but puts allow_unwrapped on the wrong (outer) level; confusion about which level may receive an unwrapped exception.","solutions":["Move allow_unwrapped=True to the inner RaisesGroup: RaisesGroup(RaisesGroup(ValueError, allow_unwrapped=True)).","If you don't care about nesting structure, use flatten_subgroups=True on the outer group instead.","Reconsider whether you need nesting at all — a flat RaisesGroup(ValueError, allow_unwrapped=True) may suffice."],"exampleFix":"// before\nRaisesGroup(RaisesGroup(ValueError), allow_unwrapped=True)\n// after\nRaisesGroup(RaisesGroup(ValueError, allow_unwrapped=True))","handlingStrategy":"validation","validationCode":"if allow_unwrapped and isinstance(expected_exception, RaisesGroup):\n    raise ValueError('move allow_unwrapped to the inner RaisesGroup')\nRaisesGroup(expected_exception, allow_unwrapped=allow_unwrapped)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Put allow_unwrapped on the innermost RaisesGroup that may receive an unwrapped exception.","Use flatten_subgroups=True on the outer group if nesting structure doesn't matter.","Re-read the nesting examples in the RaisesGroup docstring when combining flags."],"tags":["pytest","raises-group","validation"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}