pytest-datadir
pytest plugin for test data directories and files
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-datadiruv
uv add pytest-datadirpoetry
poetry add pytest-datadirInstalling 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
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-regressionsProvides pytest fixtures for writing regression…
permissive · top 5,000 on PyPI
pytest-containerA pytest plugin that automates container…
copyleft · top 15,000 on PyPI
pytest-redisA pytest plugin that provides fixtures for…
copyleft · top 15,000 on PyPI
pytest-datafilesA pytest plugin that copies specified files and…
permissive · top 15,000 on PyPI
pytest-mypy-pluginsA pytest plugin that runs type-checking tests…
permissive · top 15,000 on PyPI
pytest-pgsqlA pytest plugin that provides fixtures for…
permissive · top 15,000 on PyPI
pytest-unused-fixturesA pytest plugin that identifies and reports…
permissive · top 15,000 on PyPI
pytest-mypyIntegrates mypy static type checking into…
permissive · top 15,000 on PyPI
pytest-describeA pytest plugin that organizes tests into…
permissive · top 5,000 on PyPI
pytest-cookiesA pytest plugin that provides a `cookies`…
permissive · top 15,000 on PyPI