Skip to main content

pytest-datadir

pytest plugin for manipulating test data directories and files.

Build Status PyPI CondaForge Python Version Code style: black

Usage

pytest-datadir automatically looks for a directory matching your module's name or a global data folder.

Consider the following directory structure:

.
├── data/
│   └── hello.txt
├── test_hello/
│   └── spam.txt
└── test_hello.py

You can access file contents using the injected fixtures:

  • datadir (for module-specific test_* folders)
  • shared_datadir (for the global data folder)
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"

The contents of the data directory are copied to a temporary folder, ensuring safe file modifications without affecting other tests or original files.

Both datadir and shared_datadir fixtures return pathlib.Path objects.

lazy_datadir

Version 1.7.0 introduced the lazy_datadir fixture, which only copies files and directories when accessed via the joinpath method or the / operator.

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

Unlike datadir, lazy_datadir is an object that only implements joinpath and / operations. While not fully backward-compatible with datadir, most tests can switch to lazy_datadir without modifications.

lazy_shared_datadir

lazy_shared_datadir is similar to lazy_datadir, but applied to the shared data directory shared_datadir. That is, instead of copying all files in shared_datadir, files are only copied as necessary when accessed via joinpath or the / operator. This allows for a shared data directory to be pulled from lazily in the same manner as lazy_datadir.

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

License

MIT.

Metadata

Release files for pytest-datadir 1.9.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytest-datadir 1.9.0
File Size Uploaded Provenance Actions
pytest_datadir-1.9.0.tar.gz 13.1 kB With provenance Details for pytest_datadir-1.9.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytest-datadir 1.9.0
File Interpreter ABI Platform Actions
pytest_datadir-1.9.0-py3-none-any.whl Python 3 none any Details for pytest_datadir-1.9.0-py3-none-any.whl

Total release size: 19.5 kB

Release files / pytest_datadir-1.9.0.tar.gz

Download URL pytest_datadir-1.9.0.tar.gz
Size 13.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1e81f37069571fe283b58d8c14386898b62e54543654b6b5335d74313c16b1af
BLAKE2b-256 checksum
How to use checksums
b68b0f3460b1223d3053d355347445bc6d1a85cdc50f1fe80b17bb2b25b2e854
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Release files / pytest_datadir-1.9.0-py3-none-any.whl

Download URL pytest_datadir-1.9.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e8b071cc486deee3cc5d8fc24c41735396d1ced2e75bbb85d15b6e67b8b41acb
BLAKE2b-256 checksum
How to use checksums
355d042a244ff485e2956e1bd548eb9a8ee186a1a9fd4dfc44a3683b62f1bf01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Security for pytest-datadir 1.9.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pytest_datadir-1.9.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page