python
data_error
ai_generated
true
FileNotFoundError: [Errno 2] No such file or directory: '/repo/tests/test_parser/input.csv'
ID: python/pytest-datadir-missing-file
80%Fix Rate
80%Confidence
0Evidence
2024-06-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 0.8 | active | — | — | — |
Root Cause
pytest-datadir resolves `data/` relative to the test module's directory; the file lives in the wrong path, the plugin is not installed, or the test file was moved without moving its data directory.
generic中文
pytest-datadir 将 `data/` 解析为相对于测试模块的目录;文件路径错误、插件未安装,或测试文件移动时未一并移动数据目录。
Workarounds
-
90% success
Place data next to the test as `tests/test_parser/input.csv` and reference it via the `datadir` fixture: def test_parse(datadir): path = datadir / 'input.csv' assert path.exists() -
85% success
Or use `tmp_path` + `shutil.copy` from a committed fixtures dir: import shutil FIXTURES = Path(__file__).parent / 'fixtures' def test_parse(tmp_path): src = FIXTURES / 'input.csv' dst = tmp_path / 'input.csv' shutil.copy(src, dst)
Dead Ends
Common approaches that don't work:
-
90% fail
Breaks on CI and other machines; path does not exist there.
-
75% fail
Silently produces empty fixtures and the test asserts against wrong data.