{"record":{"id":"143604de69218842","repo":"pytest-dev/pytest","slug":"module-or-package-not-found-arg-missing-init","errorCode":null,"errorMessage":"module or package not found: {arg} (missing __init__.py?)","messagePattern":"module or package not found: (.+?) \\(missing __init__\\.py\\?\\)","errorType":"validation","errorClass":"UsageError","httpStatus":null,"severity":"error","filePath":"src/_pytest/main.py","lineNumber":1173,"sourceCode":"        raise UsageError(f\"path cannot contain [] parametrization: {arg}\")\n    parametrization = f\"{squacket}{rest}\" if squacket else None\n    module_name = None\n    if as_pypath:\n        pyarg_strpath = search_pypath(\n            strpath, consider_namespace_packages=consider_namespace_packages\n        )\n        if pyarg_strpath is not None:\n            module_name = strpath\n            strpath = pyarg_strpath\n    fspath = invocation_path / strpath\n    fspath = absolutepath(fspath)\n    if not safe_exists(fspath):\n        msg = (\n            \"module or package not found: {arg} (missing __init__.py?)\"\n            if as_pypath\n            else \"file or directory not found: {arg}\"\n        )\n        raise UsageError(msg.format(arg=arg))\n    if parts and fspath.is_dir():\n        msg = (\n            \"package argument cannot contain :: selection parts: {arg}\"\n            if as_pypath\n            else \"directory argument cannot contain :: selection parts: {arg}\"\n        )\n        raise UsageError(msg.format(arg=arg))\n    return CollectionArgument(\n        path=fspath,\n        parts=parts,\n        parametrization=parametrization,\n        module_name=module_name,\n        original_index=arg_index,\n    )\n\n\ndef is_collection_argument_subsumed_by(\n    arg: CollectionArgument, by: CollectionArgument","sourceCodeStart":1155,"sourceCodeEnd":1191,"githubUrl":"https://github.com/pytest-dev/pytest/blob/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/main.py#L1155-L1191","documentation":"main.py:1173 raises 'module or package not found: {arg} (missing __init__.py?)' when --pyargs (as_pypath=True) is used and the given module path cannot be imported/found on sys.path via search_pypath. The message hints at a missing __init__.py because that is the most common reason a package cannot be imported.","triggerScenarios":"Running 'pytest --pyargs myproj.tests.test_x' where myproj is not installed/importable; a package missing __init__.py; running from the wrong virtualenv where the module is absent; namespace package issues.","commonSituations":"Forgetting to pip install -e . the local package; missing __init__.py in a test package; wrong/activated virtualenv; the module name typo'd.","solutions":["Install the package editable: 'pip install -e .' so it is importable.","Add __init__.py to make the directory a proper package.","Confirm 'python -c \"import myproj.tests.test_x\"' works in the same environment.","Check the spelling of the dotted module path."],"exampleFix":"// before\npytest --pyargs myproj.tests.test_x  # not installed\n// after\npip install -e . && pytest --pyargs myproj.tests.test_x","handlingStrategy":"validation","validationCode":"# Verify module importability before running with --pyargs\nimport importlib, sys\ndef assert_importable(dotted: str):\n    try:\n        importlib.import_module(dotted)\n    except ImportError as e:\n        raise SystemExit(f'{dotted!r} not importable: {e}; pip install -e . or add __init__.py')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["pip install -e . the local package.","Ensure __init__.py exists in every package dir.","Validate the dotted path imports in the target venv."],"tags":["pytest","collection","pyargs","import","packaging"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}