{"record":{"id":"c2a05d2c9c908639","repo":"pytest-dev/pytest","slug":"error-importing-plugin-modname-e-args-0","errorCode":null,"errorMessage":"Error importing plugin \"{modname}\": {e.args[0]}","messagePattern":"Error importing plugin \"(.+?)\": (.+?)","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"src/_pytest/config/__init__.py","lineNumber":927,"sourceCode":"\n        importspec = \"_pytest.\" + modname if modname in builtin_plugins else modname\n        self.rewrite_hook.mark_rewrite(importspec)\n\n        if consider_entry_points:\n            loaded = self.load_setuptools_entrypoints(\"pytest11\", name=modname)\n            if loaded:\n                return\n\n        try:\n            if sys.version_info >= (3, 11):\n                mod = importlib.import_module(importspec)\n            else:\n                # On Python 3.10, import_module breaks\n                # testing/test_config.py::test_disable_plugin_autoload.\n                __import__(importspec)\n                mod = sys.modules[importspec]\n        except ImportError as e:\n            raise ImportError(\n                f'Error importing plugin \"{modname}\": {e.args[0]}'\n            ).with_traceback(e.__traceback__) from e\n\n        except Skipped as e:\n            self.skipped_plugins.append((modname, e.msg or \"\"))\n        else:\n            self.register(mod, modname)\n\n\ndef _get_plugin_specs_as_list(\n    specs: types.ModuleType | str | Sequence[str] | None,\n) -> list[str]:\n    \"\"\"Parse a plugins specification into a list of plugin names.\"\"\"\n    # None means empty.\n    if specs is None:\n        return []\n    # Workaround for #3899 - a submodule which happens to be called \"pytest_plugins\".\n    if isinstance(specs, types.ModuleType):","sourceCodeStart":909,"sourceCodeEnd":945,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/config/__init__.py#L909-L945","documentation":"Raised by _import_plugin_specs() at config/__init__.py:927 when importing a plugin module raises ImportError. The except clause at capture.py:926 catches ImportError and re-raises with a wrapped message 'Error importing plugin \"<modname>\": <original args[0]>' while preserving the original traceback via with_traceback(e.__traceback__) and chaining with `from e`. This makes the root cause visible without obscuring which plugin failed.","triggerScenarios":"A plugin referenced via `-p <name>`, an entry point, or pytest_plugins in conftest fails to import. The ImportError is caught at config/__init__.py:926 and re-raised at config/__init__.py:927-929 with modname and e.args[0].","commonSituations":"Plugin not pip-installed in the environment; plugin version incompatible with installed pytest; plugin has a transitive dependency missing; namespace conflicts after a refactor; sys.path issues preventing importlib.import_module from finding the module.","solutions":["Inspect e.args[0] in the wrapped message - it is the original ImportError text","Run `python -c 'import <plugin module>'` to reproduce the import failure directly","pip install / pip install --upgrade the offending plugin","Verify the plugin name passed to -p is the importable module name (not the distribution name)"],"exampleFix":"// before\n# plugin raises ImportError because 'foo' package is missing\npytest -p myplugin\n// after\npip install foo && pytest -p myplugin","handlingStrategy":"try-catch","validationCode":"import importlib\ntry:\n    importlib.import_module(plugin_modname)\nexcept ImportError as e:\n    print(f'Pre-check failed: {e}')","typeGuard":"def is_importable(modname: str) -> bool:\n    import importlib.util\n    return importlib.util.find_spec(modname) is not None","tryCatchPattern":"try:\n    pytest.main(['-p', plugin_name])\nexcept ImportError as e:\n    # e.args[0] contains the original message\n    print(f'Plugin import failed: {e.args[0]}')","preventionTips":["Pin plugin versions in pyproject.toml/requirements.txt to avoid surprise incompatibilities","Pre-flight plugins with importlib.util.find_spec before invoking pytest","Install plugins in the same virtualenv that runs pytest"],"tags":["plugin","import","config","dependency"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}