{"record":{"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":"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":"The non-pyargs branch at main.py:1173 raises 'file or directory not found: {arg}' when the resolved filesystem path does not exist (safe_exists returns False) and as_pypath is False. This is the standard 'the path you gave me is not on disk' error for plain file/directory arguments.","triggerScenarios":"Running 'pytest tests/test_foo.py' when that file does not exist; a typo in the path; running pytest from the wrong working directory; stale CI references after files moved.","commonSituations":"Wrong cwd when invoking pytest; renamed/moved test files; CI checkout missing the file; relative path resolved against an unexpected base.","solutions":["Verify the file/dir exists with 'ls <path>' from the directory you run pytest in.","Use an absolute path or change to the repo root before running.","If the file was moved, update the invocation/CI config.","Drop the argument to let pytest auto-collect from the default rootdir."],"exampleFix":"// before\npytest tests/old_name.py  # renamed\n// after\npytest tests/new_name.py","handlingStrategy":"validation","validationCode":"from pathlib import Path\ndef assert_exists(arg: str):\n    p = Path(arg)\n    assert p.exists(), f'path not found: {arg!r} (cwd={Path.cwd()})'\n    return arg","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify paths with ls before running pytest.","Run pytest from the repo root or use absolute paths.","Update CI configs when files move."],"tags":["pytest","collection","cli","filesystem","path"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}