--- id: pytest-datafiles version: "3.0.1" license: MIT license_treatment: permissive maintenance: active --- # pytest-datafiles — py.test plugin to create a 'tmp_path' containing predefined files/directories. License: permissive · Maintenance: active · Downloads: 123.9K/mo ## 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 above — 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 pip install pytest-datafiles uv add pytest-datafiles poetry add pytest-datafiles ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 123.9K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags pytest fixture for test data files, copy files to temp directory pytest, test file isolation pytest, pytest datafiles plugin, temporary test data setup, pytest tmp_path fixture helper, test data management pytest, pytest-plugin, test-fixtures, file-isolation [View on SkillFed](https://skillfed.io/packages/pytest-datafiles) · [View on PyPI](https://pypi.org/project/pytest-datafiles/)