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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pytest_datadir-1.8.0.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytest_datadir-1.8.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest_datadir-1.8.0.tar.gz.

File metadata

  • Download URL: pytest_datadir-1.8.0.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pytest_datadir-1.8.0.tar.gz
Algorithm Hash digest
SHA256 7a15faed76cebe87cc91941dd1920a9a38eba56a09c11e9ddf1434d28a0f78eb
MD5 b484cae6536726231dad90aa92487af3
BLAKE2b-256 b446db060b291999ca048edd06d6fa9ee95945d088edc38b1172c59eeb46ec45

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_datadir-1.8.0.tar.gz:

Publisher: deploy.yml on gabrielcnr/pytest-datadir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytest_datadir-1.8.0-py3-none-any.whl.

File metadata

  • Download URL: pytest_datadir-1.8.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.8

File hashes

Hashes for pytest_datadir-1.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c677bc097d907ac71ca418109adc3abe34cf0bddfe6cf78aecfbabd96a15cf0
MD5 0a62fd932bdf7c3cb612646975049d54
BLAKE2b-256 8f7a33895863aec26ac3bb5068a73583f935680d6ab6af2a9567d409430c3ee1

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_datadir-1.8.0-py3-none-any.whl:

Publisher: deploy.yml on gabrielcnr/pytest-datadir

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.8.0 This release

2 files

1.7.2

2 files

1.7.1

2 files

1.7.0

2 files

1.6.1

2 files

1.6.0

2 files

1.5.0

2 files

1.4.1

2 files

1.3.1

2 files

1.3.0

2 files

1.2.1

2 files

1.2.0

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

1 file

0.2.0

2 files

0.1.0

1 file

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page