{"id":"4294631925c37ad5","repo":"pytest-dev/pytest","slug":"expected-expected-but-got-type-exc-name-r","errorCode":null,"errorMessage":"Expected {expected}, but got {type(exc).__name__!r}.\nRaisesGroup does not support tuples of exception types when expecting one of several possible exception types like RaisesExc.\nIf you meant to expect a group with multiple exceptions, list them as separate arguments.","messagePattern":"Expected (.+?), but got (.+?)\\.\nRaisesGroup does not support tuples of exception types when expecting one of several possible exception types like RaisesExc\\.\nIf you meant to expect a group with multiple exceptions, list them as separate arguments\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/_pytest/raises.py","lineNumber":1027,"sourceCode":"            | RaisesGroup[BaseExcT_2]\n        ),\n        expected: str,\n    ) -> type[BaseExcT_co] | RaisesExc[BaseExcT_1] | RaisesGroup[BaseExcT_2]:\n        # verify exception type and set `self.is_baseexception`\n        match exc:\n            case RaisesGroup() if self.flatten_subgroups:\n                raise ValueError(\n                    \"You cannot specify a nested structure inside a RaisesGroup with\"\n                    \" `flatten_subgroups=True`. The parameter will flatten subgroups\"\n                    \" in the raised exceptiongroup before matching, which would never\"\n                    \" match a nested structure.\",\n                )\n            case RaisesGroup() | RaisesExc():\n                self.is_baseexception |= exc.is_baseexception\n                exc._nested = True\n                return exc\n            case tuple():\n                raise TypeError(\n                    f\"Expected {expected}, but got {type(exc).__name__!r}.\\n\"\n                    \"RaisesGroup does not support tuples of exception types when expecting one of \"\n                    \"several possible exception types like RaisesExc.\\n\"\n                    \"If you meant to expect a group with multiple exceptions, list them as separate arguments.\"\n                )\n            case _:\n                return super()._parse_exc(exc, expected)\n\n    @overload\n    def __enter__(\n        self: RaisesGroup[ExcT_1],\n    ) -> ExceptionInfo[ExceptionGroup[ExcT_1]]: ...\n    @overload\n    def __enter__(\n        self: RaisesGroup[BaseExcT_1],\n    ) -> ExceptionInfo[BaseExceptionGroup[BaseExcT_1]]: ...\n\n    def __enter__(self) -> ExceptionInfo[BaseExceptionGroup[BaseException]]:","sourceCodeStart":1009,"sourceCodeEnd":1045,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/raises.py#L1009-L1045","documentation":"Unlike RaisesExc/pytest.raises, RaisesGroup does NOT accept a tuple of exception types as a single positional argument. To expect a group with multiple exceptions, pass them as separate positional arguments.","triggerScenarios":"Calling RaisesGroup((ValueError, TypeError)) — a single tuple argument. Hits raises.py:1027 in _parse_excgroup via the `case tuple():` branch.","commonSituations":"Developer copies the tuple syntax familiar from pytest.raises(ExceptionGroup, (A, B)) into RaisesGroup; programmatic construction passes a tuple by mistake.","solutions":["Spread the types as separate positional args: RaisesGroup(ValueError, TypeError).","If you hold a tuple variable, splat it: RaisesGroup(*my_exc_tuple).","If you meant 'one of several types in a single slot', use RaisesExc(check=lambda e: isinstance(e, (...))) instead."],"exampleFix":"// before\nRaisesGroup((ValueError, TypeError))\n// after\nRaisesGroup(ValueError, TypeError)","handlingStrategy":"validation","validationCode":"if isinstance(expected, tuple):\n    expected = list(expected)  # will be spread\nRaisesGroup(*expected)","typeGuard":"def is_flat_exception_list(exc) -> TypeGuard[list]:\n    return not isinstance(exc, tuple)","tryCatchPattern":null,"preventionTips":["Pass multiple expected types as separate positional args, not a tuple.","Splat existing tuples: RaisesGroup(*my_tuple).","Remember RaisesGroup's API differs from raises — no tuple-of-types shortcut."],"tags":["pytest","raises-group","validation"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}