Skip to main content

pytest plugin for test data directories and files

Project description

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.

License

MIT.

Project details


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.7.2.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

pytest_datadir-1.7.2-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pytest_datadir-1.7.2.tar.gz
  • Upload date:
  • Size: 11.3 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.7.2.tar.gz
Algorithm Hash digest
SHA256 15f5228a35d0a3205e4968e75d3b9cca91762424e1eafc21eb637d380a48443e
MD5 7fbcca289428781c63b53378f2d26f0f
BLAKE2b-256 2f167701db071caf7d8f7226b76323de40a09d2a391c7d064cda072d45a87c7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_datadir-1.7.2.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.7.2-py3-none-any.whl.

File metadata

  • Download URL: pytest_datadir-1.7.2-py3-none-any.whl
  • Upload date:
  • Size: 6.3 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.7.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8392ba0e9eaf37030e663dcd91cc5123dec99c44300f0c5eac44f35f13f0e086
MD5 5c0187661fcce5405a3bed0ea8bd4648
BLAKE2b-256 d361a06f3406852534e186413c75f544c90251db00fd8eb9625ee3ac239499f3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytest_datadir-1.7.2-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.

Supported by

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