skillfed

pytest-datadir

pytest plugin for test data directories and files

pytest-datadir v1.8.0 1.8M downloads/30d#3,576 on PyPI275
Permissive license MIT Active released

What it is and what it does

pytest-datadir is a pytest plugin that simplifies working with test data by providing fixtures that automatically locate and manage test data files. It supports two organizational patterns: module-specific data directories (named to match your test module) and a shared global data folder. The plugin copies data to temporary locations during test execution, ensuring test isolation and preventing accidental modifications to original files.

The package offers three main fixtures: datadir for module-specific data, shared_datadir for global test data, and lazy variants (lazy_datadir and lazy_shared_datadir) that defer copying until files are actually accessed. All fixtures return pathlib.Path objects, making file operations straightforward. It requires Python 3.8 or later and integrates seamlessly into existing pytest workflows.

Use it for:

  • Load fixture files (JSON, CSV, XML) in unit tests without modifying originals or managing temporary cleanup.
  • Share common test data across multiple test modules via a global data directory.
  • Test file I/O operations safely by working with isolated copies that don't affect the source data.
  • Reduce test setup boilerplate by automatically discovering and preparing test data based on directory naming conventions.
  • Optimize test performance with lazy_datadir when only a subset of test data files are needed per test.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

A pytest plugin that provides fixtures for safely accessing test data files organized in module-specific or shared directories, automatically copying them to temporary locations during test runs.

Yes. This is a stable, well-maintained plugin (active since 2015, currently at version 1.8.0) with no security vulnerabilities, low install friction, and a clear, focused purpose. If your test suite uses file-based fixtures, it eliminates manual directory management and temporary file cleanup, making tests cleaner and safer. The permissive MIT license poses no restrictions.

Install

pytest-datadir on PyPI

pip

pip install pytest-datadir

uv

uv add pytest-datadir

poetry

poetry add pytest-datadir

Installing pytest-datadir

Before you install

Low friction: pure Python wheel with only pytest as a runtime dependency. Actively maintained with a recent release (2025-07-30) and no known vulnerabilities.

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

# In test_hello.py with data/hello.txt and test_hello/spam.txt present:
from pathlib import Path

def test_read_global(shared_datadir):
    contents = (shared_datadir / "hello.txt").read_text()
    assert contents == "Hello World!\n"

def test_read_module(datadir):
    contents = (datadir / "spam.txt").read_text()
    assert contents == "eggs\n"

Requires Python 3.8 or later; test data directories must follow naming conventions (module-specific test_* folders or a global data folder).

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 — 380 days since the last release
Last repo commit
First released
Downloads 1,767,458/month — #3,576 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pytest_datadir-1.8.0-py3-none-any.whl

Keywords: pytest, test, unittest, directory, file

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Quality AssuranceTopic :: Software Development :: Testing

Tags

pytest test data fixturestest file directory managementpytest temporary data handlingtest data isolation pluginpytest datadir fixture
pytest-plugintest-fixturesfile-handling

More Testing packages