pytest-datafiles
py.test plugin to create a 'tmp_path' containing predefined files/directories.
What it is and what it does
pytest-datafiles is a pytest plugin that automates the setup of test data by copying files and directories into a temporary directory before each test runs. You decorate a test function with @pytest.mark.datafiles() and list the files or directories you want copied, then receive a pathlib.Path object pointing to the temporary copy. This keeps your original test data untouched across test runs and ensures each test works on its own isolated copy.
The plugin is useful when tests need to read or modify files without side effects—common scenarios include testing on large media files, image processing, or any workflow where you want to verify file handling without corrupting your test fixtures. It supports both string paths and pathlib.Path objects, offers options to control directory nesting and duplicate file handling, and integrates seamlessly into pytest's fixture and marker system.
Use it for:
- Testing video or image processing code on large files stored outside the test suite without modifying originals
- Running multiple tests on the same fixture files while ensuring each test gets an independent copy
- Verifying file I/O and modification logic in isolation, with automatic cleanup after each test
- Setting up complex directory structures for integration tests that need realistic file layouts
- Testing file-based tools or utilities where you need to confirm they don't corrupt the input data
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
A pytest plugin that copies specified files and directories into a temporary directory before each test, ensuring test isolation without modifying original files.
Yes. This is a stable, low-friction plugin (pure Python, only pytest dependency) with active maintenance and no known vulnerabilities. It solves a common testing problem—data isolation—cleanly and has been proven in production since 2015. Install it if your tests work with files and you want to avoid fixture pollution or manual cleanup.
Install
pytest-datafiles on PyPI
pip
pip install pytest-datafilesuv
uv add pytest-datafilespoetry
poetry add pytest-datafilesInstalling pytest-datafiles
Before you install
Low friction: pure Python wheel with only pytest as a runtime dependency. Actively maintained since 2015 with recent updates; the maintainer notes little activity because the plugin is stable and works as intended.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and commercial projects with minimal obligations.
Quickstart
pip install pytest-datafiles
import pytest
from pathlib import Path
@pytest.mark.datafiles('/path/to/file.txt')
def test_example(datafiles):
# datafiles is a pathlib.Path object pointing to the temp directory
assert (datafiles / 'file.txt').exists()
Verify before relying
- Whether the plugin works with pytest plugins that also manipulate tmp_path or fixture scoping
- Performance characteristics when copying very large file trees or many files per test
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — pytest |
| Maintenance | actively maintained — 222 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 123,874/month — #11,893 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pytest_datafiles-3.0.1-py3-none-any.whl
Keywords: datafiles, pytest, tmp_path
Tags
More Testing packages
Pluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
pytestpytest is a testing framework that lets you…
permissive · top 100 on PyPI
virtualenvvirtualenv creates isolated Python environments…
permissive · top 100 on PyPI
coverageCoverage.py measures which lines of Python code…
permissive · top 1,000 on PyPI
pytest-asynciopytest-asyncio is a pytest plugin that enables…
permissive · top 1,000 on PyPI
pytest-json-ctrfA pytest plugin that generates test reports in…
permissive · top 1,000 on PyPI
pytest-helpers-namespaceProvides a pytest namespace for registering and…
permissive · top 15,000 on PyPI
pytest-regressionsProvides pytest fixtures for writing regression…
permissive · top 5,000 on PyPI
pytest-datadirA pytest plugin that provides fixtures for…
permissive · top 5,000 on PyPI
pytest-xprocesspytest-xprocess manages external processes…
permissive · top 15,000 on PyPI
pytest-pythonpathAdds directories to Python's import path before…
permissive · top 15,000 on PyPI
pytest-casespytest-cases lets you separate test case data…
permissive · top 5,000 on PyPI
pytest-freezegunpytest-freezegun provides a pytest plugin that…
permissive · top 5,000 on PyPI
pytest-loggingA pytest plugin that configures Python logging…
permissive · top 15,000 on PyPI
pytest-error-for-skipsA pytest plugin that converts skipped tests…
permissive · top 15,000 on PyPI