{"record":{"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/0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc/src/_pytest/pytester.py#L971-L1007","documentation":"Thrown by Pytester.copy_example() when an explicit `name` was passed but the resulting path is neither an existing directory nor a file. This is the fallback after the name-based joinpath found nothing on disk.","triggerScenarios":"Calling copy_example('nonexistent.py') where the file doesn't exist in example_dir; passing a relative path with wrong separators; the example was moved/deleted between writing and running the test.","commonSituations":"Example files renamed or relocated; CI running against a shallow checkout missing example assets; case-sensitivity mismatch on case-sensitive filesystems.","solutions":["Verify the path exists under pytester_example_dir with Path.exists().","Print example_dir and list its contents to confirm the expected name.","Check for case mismatches and OS-specific path separators."],"exampleFix":"// before\npytester.copy_example(\"MyExample.py\")\n// after\nimport pathlib\nexample_dir = pathlib.Path(pytester._request.config.getini('pytester_example_dir'))\nprint(list(example_dir.iterdir()))\npytester.copy_example(\"myexample.py\")","handlingStrategy":"validation","validationCode":"example_dir = pytester._request.config.rootpath / pytester._request.config.getini('pytester_example_dir')\ntarget = example_dir / name\nif not target.exists():\n    pytest.fail(f'example not found: {target}. available: {list(example_dir.iterdir())}')\npytester.copy_example(name)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Verify the example path exists before calling copy_example.","List example_dir contents to catch case/naming mismatches.","Use consistent casing across example files and test code."],"tags":["pytester","copy-example","filesystem","lookup"],"backgroundTag":null,"analyzedSha":"0d6fbdeffa57c796123f62f81f7dd370d9b7ecdc","analyzedAt":"2026-08-11T20:52:36.969Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}