--- id: pytest-datadir version: "1.8.0" license: MIT license_treatment: permissive maintenance: active --- # pytest-datadir — pytest plugin for test data directories and files License: permissive · Maintenance: active · Downloads: 1.8M/mo ## 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 above — 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 pip install pytest-datadir uv add pytest-datadir 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_current - Install friction: low - Maintenance: active - Downloads: 1.8M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags pytest test data fixtures, test file directory management, pytest temporary data handling, test data isolation plugin, pytest datadir fixture, pytest-plugin, test-fixtures, file-handling [View on SkillFed](https://skillfed.io/packages/pytest-datadir) · [View on PyPI](https://pypi.org/project/pytest-datadir/)