{"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/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/raises.py#L257-L293","documentation":"Raised in the function-call form of pytest.raises when the second positional argument (func) is not callable. The function-call signature requires func to be a callable that will be invoked with the trailing *args/**kwargs.","triggerScenarios":"Calling pytest.raises(ValueError, 42), pytest.raises(ValueError, 'notafunc'), or pytest.raises(ValueError, some_object) where the second arg is not callable. Hits raises.py:274 (`if not callable(func):`).","commonSituations":"Accidentally calling the function (passing its return value) instead of passing the reference; passing a module or data object by mistake; a refactor renames the function so the name no longer resolves to a callable.","solutions":["Pass the callable itself, not its result: drop the trailing parentheses on the function name.","Verify with callable(obj) before passing when the value comes from a dynamic source.","Switch to the context-manager form (with pytest.raises(ValueError):) to avoid the positional-func footgun entirely.","Check for a typo or stale reference if a refactor may have removed the callable."],"exampleFix":"// before\npytest.raises(ValueError, my_func())\n// after\npytest.raises(ValueError, my_func)","handlingStrategy":"type-guard","validationCode":"if not callable(func):\n    raise TypeError(f'{func!r} is not callable')\npytest.raises(ValueError, func)","typeGuard":"from collections.abc import Callable\ndef is_callable_func(f) -> TypeGuard[Callable]:\n    return callable(f)","tryCatchPattern":null,"preventionTips":["Pass the function reference (no parentheses), not its return value.","Prefer the context-manager form (with pytest.raises(Exc):) to avoid the positional func entirely.","When func comes from a dynamic source, assert callable(func) first."],"tags":["pytest","raises","validation","callable"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}