{"record":{"id":"5ebbfd321fedd03c","repo":"pytest-dev/pytest","slug":"module-name-r-has-no-attribute-name-r","errorCode":null,"errorMessage":"module {__name__!r} has no attribute {name!r}","messagePattern":"module (.+?) has no attribute (.+?)","errorType":"exception","errorClass":"AttributeError","httpStatus":null,"severity":"warning","filePath":"src/_pytest/python.py","lineNumber":1842,"sourceCode":"            style = \"long\"\n        return self._repr_failure_py(excinfo, style=style)\n\n\nclass FunctionDefinition(Function):\n    \"\"\"This class is a stop gap solution until we evolve to have actual function\n    definition nodes and manage to get rid of ``metafunc``.\"\"\"\n\n    def runtest(self) -> None:\n        raise RuntimeError(\"function definitions are not supposed to be run as tests\")\n\n    setup = runtest\n\n\ndef __getattr__(name: str) -> object:\n    if name == \"CallSpec2\":\n        warnings.warn(CALLSPEC2_RENAMED, stacklevel=2)\n        return CallSpec\n    raise AttributeError(f\"module {__name__!r} has no attribute {name!r}\")\n","sourceCodeStart":1824,"sourceCodeEnd":1843,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/python.py#L1824-L1843","documentation":"Thrown by the module-level __getattr__ in _pytest/python.py for any attribute access not special-cased. Currently only 'CallSpec2' is special-cased (deprecated alias); everything else falls through to this generic AttributeError.","triggerScenarios":"Doing from _pytest.python import SomeName where SomeName doesn't exist; accessing _pytest.python.CallSpec2 (deprecated warning then redirect, but other names error); typos in internal imports by plugins.","commonSituations":"Plugins reaching into _pytest.python internals; renamed/removed private names across pytest versions; IDE auto-import suggestions for non-existent names.","solutions":["Import the name from the public pytest namespace instead of _pytest.python.","Check the pytest version's source for the correct name; it may have been renamed.","Avoid relying on private _pytest.* modules in external plugins."],"exampleFix":"// before\nfrom _pytest.python import CallSpec2  # deprecated, will warn\n// after\nfrom _pytest.python import CallSpec","handlingStrategy":"validation","validationCode":"import importlib\nmod = importlib.import_module('_pytest.python')\nif not hasattr(mod, name):\n    raise AttributeError(f'_pytest.python has no {name!r}; check for renames')","typeGuard":"def module_has_attr(module, name: str) -> bool:\n    return hasattr(module, name)","tryCatchPattern":null,"preventionTips":["Import from the public pytest package, not _pytest.python internals.","Check pytest source/changelog for renamed private names.","Avoid depending on private modules in external plugins."],"tags":["getattr","attribute-access","internal","deprecation"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}