{"record":{"id":"85f37b89487a62e0","repo":"pytest-dev/pytest","slug":"func-r-object-type-type-func-must-be-calla","errorCode":null,"errorMessage":"{func!r} object (type: {type(func)}) must be callable","messagePattern":"(.+?) object \\(type: (.+?)\\) must be callable","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/_pytest/raises.py","lineNumber":275,"sourceCode":"    if func is None and not args:\n        if set(kwargs) - {\"match\", \"check\", \"expected_exception\"}:\n            msg = \"Unexpected keyword arguments passed to pytest.raises: \"\n            msg += \", \".join(sorted(kwargs))\n            msg += \"\\nUse context-manager form instead?\"\n            raise TypeError(msg)\n\n        if expected_exception is None:\n            return RaisesExc(**kwargs)\n        return RaisesExc(expected_exception, **kwargs)\n\n    if not expected_exception:\n        raise ValueError(\n            f\"Expected an exception type or a tuple of exception types, but got `{expected_exception!r}`. \"\n            f\"Raising exceptions is already understood as failing the test, so you don't need \"\n            f\"any special code to say 'this should never raise an exception'.\"\n        )\n    if not callable(func):\n        raise TypeError(f\"{func!r} object (type: {type(func)}) must be callable\")\n    with RaisesExc(expected_exception) as excinfo:\n        func(*args, **kwargs)\n    try:\n        return excinfo\n    finally:\n        del excinfo\n\n\n# note: RaisesExc/RaisesGroup uses fail() internally, so this alias\n#  indicates (to [internal] plugins?) that `pytest.raises` will\n#  raise `_pytest.outcomes.Failed`, where\n#  `outcomes.Failed is outcomes.fail.Exception is raises.Exception`\n# note: this is *not* the same as `_pytest.main.Failed`\n# note: mypy does not recognize this attribute, and it's not possible\n#  to use a protocol/decorator like the others in outcomes due to\n#  https://github.com/python/mypy/issues/18715\nraises.Exception = fail.Exception  # type: ignore[attr-defined]\n","sourceCodeStart":257,"sourceCodeEnd":293,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/raises.py#L257-L293","documentation":"Thrown by pytest.raises() in the function-call form when `func` (the second positional argument) is not callable. pytest raises expects a callable to invoke; passing a value, instance, or non-callable object is a misuse.","triggerScenarios":"Calling pytest.raises(ValueError, 'not a function'); pytest.raises(ValueError, some_object); passing the result of calling a function instead of the function itself: pytest.raises(ValueError, myfunc()).","commonSituations":"Forgetting to pass the callable (passing its return value); passing a string instead of a function; passing an instance of a non-callable class; copy-paste errors.","solutions":["Pass the callable itself, not its result: pytest.raises(ValueError, myfunc) (no parens).","If you need args, use pytest.raises(ValueError, myfunc, arg1, arg2).","Prefer the context-manager form to avoid this footgun: with pytest.raises(ValueError): myfunc(arg1)."],"exampleFix":"// before\npytest.raises(ValueError, myfunc())  # calls myfunc first\n// after - function form\npytest.raises(ValueError, myfunc, arg1)\n// or context-manager form\nwith pytest.raises(ValueError):\n    myfunc(arg1)","handlingStrategy":"type-guard","validationCode":"if not callable(func):\n    raise TypeError(f'{func!r} is not callable; pass the function, not its result')\npytest.raises(ValueError, func)","typeGuard":"from collections.abc import Callable\ndef is_callable_for_raises(func: object) -> bool:\n    return callable(func)","tryCatchPattern":null,"preventionTips":["Pass the callable itself, not its invocation result.","Prefer the context-manager form to sidestep the footgun.","Use pytest.raises(Exc, func, *args) to pass arguments."],"tags":["raises","callable","type-error","api-misuse"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}