Install & Compatibility
Where this runs
tested against v1.8.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 31.1MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 2.7s · import 0.000s · 32MB
30MB installed
● package 30MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
datadir
✓ def test_something(datadir):
pytest-datadir provides fixtures directly; no explicit 'import from pytest_datadir' statements are typically needed in test files. The fixtures `datadir`, `shared_datadir`, `lazy_datadir`, and `lazy_shared_datadir` are automatically discovered by pytest.
shared_datadir
✓ def test_something(shared_datadir):
pytest-datadir provides fixtures directly; no explicit 'import from pytest_datadir' statements are typically needed in test files. The fixtures `datadir`, `shared_datadir`, `lazy_datadir`, and `lazy_shared_datadir` are automatically discovered by pytest.
lazy_datadir
✓ def test_something(lazy_datadir):
Introduced in v1.7.0. pytest-datadir provides fixtures directly; no explicit 'import from pytest_datadir' statements are typically needed in test files. The fixtures `datadir`, `shared_datadir`, `lazy_datadir`, and `lazy_shared_datadir` are automatically discovered by pytest.
lazy_shared_datadir
✓ def test_something(lazy_shared_datadir):
Introduced in v1.8.0. pytest-datadir provides fixtures directly; no explicit 'import from pytest_datadir' statements are typically needed in test files. The fixtures `datadir`, `shared_datadir`, `lazy_datadir`, and `lazy_shared_datadir` are automatically discovered by pytest.
To use `pytest-datadir`, organize your test data in a `data` directory (for global data) or subdirectories named after your test modules (e.g., `test_module/`) within your test folder. The `datadir` fixture provides access to module-specific data, while `shared_datadir` provides access to global data. Both return `pathlib.Path` objects pointing to temporary copies of your data.
# File: data/hello.txt
Hello World!
# File: test_hello/spam.txt
eggs
# File: test_hello.py
import pytest
def test_read_global(shared_datadir):
# Accesses data from the global 'data' directory
contents = (shared_datadir / "hello.txt").read_text()
assert contents == "Hello World!\n"
def test_read_module(datadir):
# Accesses data from the module-specific 'test_hello' directory
contents = (datadir / "spam.txt").read_text()
assert contents == "eggs\n"
Debug
Known issues
breakingPython 2.7, 3.4, 3.5, and 3.7 are no longer supported. Version 1.4.0 dropped support for Python 2.7, 3.4, and 3.5. Version 1.5.0 dropped support for Python 3.7. The current minimum Python version required is 3.8.fixUpgrade to Python 3.8 or a newer supported version.
affects: >=1.4.0, >=1.5.0
breakingpytest version 7.0 or newer is now required. Older versions of pytest are not supported by recent releases of pytest-datadir.fixUpgrade your `pytest` installation to version 7.0 or higher: `pip install --upgrade pytest`.
affects: >=1.6.1
gotchaThe `datadir` and `shared_datadir` fixtures eagerly copy all associated test data files to a temporary directory at the start of the test. For large data sets or numerous small files, this can introduce performance overhead.fixFor versions 1.7.0 and later, consider using `lazy_datadir` or `lazy_shared_datadir` fixtures. These fixtures only copy files or directories when they are explicitly accessed via `joinpath` or the `/` operator, reducing initial setup time and resource usage.
affects: <1.7.0 (primary concern), all versions (performance consideration)
gotchaThe `original_datadir` fixture changed its scope from function-scoped to module-scoped in version 1.6.0. This might affect tests that relied on its previous behavior.fixReview tests that use `original_datadir` and adjust them if they implicitly depended on a function-level scope. If you need function-level isolation for original data, you might need to manually copy from `original_datadir` within your test function or use `datadir` for the temporary copy behavior.
affects: >=1.6.0
deprecatedThe underlying pytest `tmpdir` fixture, which returns a `py.path.local` object, has been deprecated by pytest itself in favor of `tmp_path`, which returns a `pathlib.Path` object. While `pytest-datadir` internally transitioned to `tmp_path` in v1.4.1, users migrating older tests or using `tmpdir` directly should be aware.fixPrefer `tmp_path` over `tmpdir` in your own fixtures and test code. `pytest-datadir` fixtures (`datadir`, `shared_datadir`, etc.) already return `pathlib.Path` objects, aligning with the modern `pytest` approach.
affects: All versions of `pytest-datadir` with older `pytest` versions, specifically `pytest` core versions >=7.0
Upgrade
Version history
1.8.0latest on PyPI · released Jul 30, 2025
Audit
Dependencies
pytestrequiredCore testing framework; pytest-datadir is a plugin for pytest.
pythonrequiredRequires Python 3.8 or newer.