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.

Release files for pytest-datadir 1.8.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.8.0
File Size Uploaded
pytest_datadir-1.8.0.tar.gz 11.8 kB Details

Built distribution (wheel)

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

Total release size: 18.4 kB

Release files / pytest_datadir-1.8.0.tar.gz

Download URL pytest_datadir-1.8.0.tar.gz
Size 11.8 kB
Tags Source
SHA-256 checksum
How to use checksums
7a15faed76cebe87cc91941dd1920a9a38eba56a09c11e9ddf1434d28a0f78eb
BLAKE2b-256 checksum
How to use checksums
b446db060b291999ca048edd06d6fa9ee95945d088edc38b1172c59eeb46ec45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

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 Jul 30, 2025.

Transparency log

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

Download URL pytest_datadir-1.8.0-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c677bc097d907ac71ca418109adc3abe34cf0bddfe6cf78aecfbabd96a15cf0
BLAKE2b-256 checksum
How to use checksums
8f7a33895863aec26ac3bb5068a73583f935680d6ab6af2a9567d409430c3ee1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.8

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 Jul 30, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

1.8.0 This release

2 release files

1.7.2

2 release files

1.7.1

2 release files

1.7.0

2 release files

1.6.1

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.1

2 release files

1.2.0

2 release files

1.1.0

2 release files

1.0.1

2 release files

1.0.0

1 release file

0.2.0

2 release files

0.1.0

1 release file

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