{"id":"3f4b7831762d3ade","repo":"pytest-dev/pytest","slug":"file-or-directory-not-found-arg","errorCode":null,"errorMessage":"file or directory not found: {arg}","messagePattern":"file or directory not found: (.+?)","errorType":"exception","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/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/main.py#L1155-L1191","documentation":"Raised by `resolve_collection_argument` (filesystem path mode) when the given file or directory does not exist on disk (`safe_exists(fspath)` is false). The argument is reported verbatim. This is the generic \"no such path\" collection error.","triggerScenarios":"Running `pytest tests/test_missing.py` or `pytest ./wrong_dir` where the path does not exist relative to the invocation path. Typo in path, wrong cwd, or a generated test file that was not created.","commonSituations":"Typo in the test path. Running pytest from the wrong working directory. CI checkout missing generated test files. Shell glob producing no matches and passing a literal pattern.","solutions":["Verify the path exists: `ls <path>` from the same cwd pytest runs in.","Run pytest from the repository root or pass an absolute path.","Fix typos or regenerate the missing test file.","If using globs, ensure the shell expands them (do not quote unintended literals)."],"exampleFix":"// before\n$ pytest tests/test_foo.py   # typo / wrong dir\n// after\n$ pytest tests/test_foo.py   # after cd to repo root, or:\n$ pytest /abs/path/to/tests/test_foo.py","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\ndef path_exists(arg: str, root: Path = Path.cwd()) -> bool:\n    return (root / arg).exists()","typeGuard":"def is_existing_path(arg: str) -> bool:\n    from pathlib import Path\n    return Path(arg).exists()","tryCatchPattern":null,"preventionTips":["Verify paths with ls before passing them to pytest.","Run pytest from a stable cwd (repo root).","Use absolute paths in CI to avoid cwd drift."],"tags":["pytest","collection","cli","filesystem","usageerror"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}