skillfed

pytest-datafiles

py.test plugin to create a 'tmp_path' containing predefined files/directories.

pytest-datafiles v3.0.1 123.9K downloads/30d#11,893 on PyPI106
Permissive license MIT Active released

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-datafiles

uv

uv add pytest-datafiles

poetry

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 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

Development Status :: 5 - Production/StableFramework :: PytestIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Testing

Tags

pytest fixture for test data filescopy files to temp directory pytesttest file isolation pytestpytest datafiles plugintemporary test data setuppytest tmp_path fixture helpertest data management pytest
pytest-plugintest-fixturesfile-isolation

More Testing packages