{"record":{"id":"78468f233d41b03b","repo":"pytest-dev/pytest","slug":"pdbcls-could-not-import-value-r-exc","errorCode":null,"errorMessage":"--pdbcls: could not import {value!r}: {exc}","messagePattern":"--pdbcls: could not import (.+?): (.+?)","errorType":"validation","errorClass":"UsageError","httpStatus":null,"severity":"error","filePath":"src/_pytest/debugging.py","lineNumber":135,"sourceCode":"        usepdb_cls = cls._config.getvalue(\"usepdb_cls\")\n\n        if cls._wrapped_pdb_cls and cls._wrapped_pdb_cls[0] == usepdb_cls:\n            return cls._wrapped_pdb_cls[1]\n\n        if usepdb_cls:\n            modname, classname = usepdb_cls\n\n            try:\n                mod = importlib.import_module(modname)\n\n                # Handle --pdbcls=pdb:pdb.Pdb (useful e.g. with pdbpp).\n                parts = classname.split(\".\")\n                pdb_cls = getattr(mod, parts[0])\n                for part in parts[1:]:\n                    pdb_cls = getattr(pdb_cls, part)\n            except Exception as exc:\n                value = \":\".join((modname, classname))\n                raise UsageError(\n                    f\"--pdbcls: could not import {value!r}: {exc}\"\n                ) from exc\n        else:\n            import pdb\n\n            pdb_cls = pdb.Pdb\n\n        wrapped_cls = cls._get_pdb_wrapper_class(pdb_cls, capman)\n        cls._wrapped_pdb_cls = (usepdb_cls, wrapped_cls)\n        return wrapped_cls\n\n    @classmethod\n    def _get_pdb_wrapper_class(cls, pdb_cls, capman: CaptureManager | None):\n        import _pytest.config\n\n        class PytestPdbWrapper(pdb_cls):\n            _pytest_capman = capman\n            _continued = False","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/debugging.py#L117-L153","documentation":"The --pdbcls option takes a 'module:Class' (or module:a.b.Class) specifier. pytest imports the module, then walks the dotted attribute path to resolve the class. If import or attribute access fails for any reason, pytest wraps the original exception in UsageError, naming the full specifier and the underlying error so the user can diagnose.","triggerScenarios":"--pdbcls=pdbpdb:Pdb where pdbpdb is not installed; --pdbcls=pdb:NoSuchClass (attribute missing); --pdbcls=pdbpp:pdb.Pdb where pdbpp is installed but the dotted path is wrong; import-time error inside the target module.","commonSituations":"Forgetting to pip install the debugger (e.g. pdbpp, ipdb); version change that renamed the class; typo in the module or class name; the module raises on import due to a missing dependency.","solutions":["Confirm the package is installed in the active environment: pip show <pkg>.","Verify the class path by importing it in a Python REPL: from <module> import <Class>.","Fix the specifier to match the package's actual module and class names, e.g. --pdbcls=IPython.terminal.debugger:TerminalPdb for ipdb."],"exampleFix":"// before\npytest --pdbcls=pdbpp:ppdb test_x.py\n// after\npip install pdbpp\npytest --pdbcls=pdbpp:pdb.Pdb test_x.py","handlingStrategy":"validation","validationCode":"import importlib\n\ndef validate_pdbcls(spec: str) -> None:\n    modname, _, classname = spec.partition(':')\n    assert classname, 'expected module:Class'\n    mod = importlib.import_module(modname)\n    obj = mod\n    for part in classname.split('.'):\n        obj = getattr(obj, part)\n    assert callable(obj), f'{spec} did not resolve to a class'","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Install the debugger package before passing --pdbcls.","Verify the module:Class path in a REPL before scripting pytest.","Pin debugger versions to avoid class-path renames."],"tags":["cli","debugging","pdb","import"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}