{"id":"ff00675518ec2775","repo":"pytest-dev/pytest","slug":"example-example-path-is-not-found-as-a-file-or","errorCode":null,"errorMessage":"example \"{example_path}\" is not found as a file or directory","messagePattern":"example \"(.+?)\" is not found as a file or directory","errorType":"exception","errorClass":"LookupError","httpStatus":null,"severity":"error","filePath":"src/_pytest/pytester.py","lineNumber":989,"sourceCode":"                example_path = maybe_dir\n            elif maybe_file.is_file():\n                example_path = maybe_file\n            else:\n                raise LookupError(\n                    f\"{func_name} can't be found as module or package in {example_dir}\"\n                )\n        else:\n            example_path = example_dir.joinpath(name)\n\n        if example_path.is_dir() and not example_path.joinpath(\"__init__.py\").is_file():\n            shutil.copytree(example_path, self.path, symlinks=True, dirs_exist_ok=True)\n            return self.path\n        elif example_path.is_file():\n            result = self.path.joinpath(example_path.name)\n            shutil.copy(example_path, result)\n            return result\n        else:\n            raise LookupError(\n                f'example \"{example_path}\" is not found as a file or directory'\n            )\n\n    def getnode(self, config: Config, arg: str | os.PathLike[str]) -> Collector | Item:\n        \"\"\"Get the collection node of a file.\n\n        :param config:\n           A pytest config.\n           See :py:meth:`parseconfig` and :py:meth:`parseconfigure` for creating it.\n        :param arg:\n            Path to the file.\n        :returns:\n            The node.\n        \"\"\"\n        session = Session.from_config(config)\n        assert \"::\" not in str(arg)\n        p = Path(os.path.abspath(arg))\n        config.hook.pytest_sessionstart(session=session)","sourceCodeStart":971,"sourceCodeEnd":1007,"githubUrl":"https://github.com/pytest-dev/pytest/blob/98b357f69e380da908740a212288d73b2ee06687/src/_pytest/pytester.py#L971-L1007","documentation":"Raised by Pytester.copy_example when an explicit name argument was given but the resulting path under example_dir is neither an existing file nor an existing directory. This is the explicit-name counterpart to error 147; the path was constructed but does not resolve to anything on disk.","triggerScenarios":"Calling pytester.copy_example('nonexistent.py') where that file does not exist relative to example_dir; passing a relative path that does not resolve; the example was deleted or never committed.","commonSituations":"Typo in the example name; renaming/moving example files without updating test references; examples excluded from the VCS checkout or Docker context.","solutions":["Verify the exact filename exists under the configured pytester_example_dir.","Correct the name argument to match the actual file/directory path.","Ensure example files are committed and included in CI artifacts/checkouts."],"exampleFix":"// before\npytester.copy_example(\"featue.py\")  # typo\n// after\npytester.copy_example(\"feature.py\")","handlingStrategy":"validation","validationCode":"from pathlib import Path\n\nexample_root = Path(pytestconfig.rootpath) / pytestconfig.getini(\"pytester_example_dir\")\ntarget = example_root / name\nassert target.is_file() or target.is_dir(), f\"{target} does not exist\"\npytester.copy_example(name)","typeGuard":null,"tryCatchPattern":"try:\n    pytester.copy_example(name)\nexcept LookupError as e:\n    raise AssertionError(f\"example {name!r} not found under example dir: {e}\") from e","preventionTips":["Double-check example filenames for typos.","Ensure examples are committed and present in CI checkouts.","Use a constant for shared example names."],"tags":["pytester","examples","file-not-found"],"analyzedSha":"98b357f69e380da908740a212288d73b2ee06687","analyzedAt":"2026-08-04T20:26:34.442Z","schemaVersion":2}