{"record":{"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/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/raises.py#L1009-L1045","documentation":"Raised by RaisesGroup._parse_excgroup when a tuple is passed as an expected exception. Unlike RaisesExc (which accepts tuples to mean 'one of several'), RaisesGroup expects each candidate as a separate positional argument representing members of the group. Passing a tuple is ambiguous with group membership, so pytest rejects it with a TypeError and directs the user to list exceptions as separate arguments.","triggerScenarios":"RaisesGroup((ValueError, KeyError)); RaisesGroup(exc_tuple). The `case tuple()` arm of the match statement fires.","commonSituations":"Carrying over pytest.raises(ValueError, KeyError) or RaisesExc((ValueError, KeyError)) habits into RaisesGroup; building a RaisesGroup from a programmatically-built tuple of types.","solutions":["Splat the tuple into positional arguments: RaisesGroup(*exc_tuple).","List the group members as separate arguments: RaisesGroup(ValueError, KeyError).","If you actually want 'one of several' (not group membership), use RaisesExc((ValueError, KeyError)) instead of RaisesGroup."],"exampleFix":"// before\nwith pytest.raises(RaisesGroup((ValueError, KeyError))):\n    ...\n// after\nwith pytest.raises(RaisesGroup(ValueError, KeyError)):\n    ...\n// or splat:\nwith pytest.raises(RaisesGroup(*candidates)):\n    ...","handlingStrategy":"validation","validationCode":"assert not isinstance(expected_exception, tuple), 'RaisesGroup expects separate args, not a tuple; use RaisesGroup(*tuple)'","typeGuard":"def raisesgroup_arg_not_tuple(expected_exception) -> bool:\n    return not isinstance(expected_exception, tuple)","tryCatchPattern":null,"preventionTips":["Pass group members as separate positional args to RaisesGroup.","Splat pre-built tuples: RaisesGroup(*candidates).","Use RaisesExc((A, B)) for 'one of several' matching, not RaisesGroup."],"tags":["pytest","raises","raisesgroup","tuple-argument","validation"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}