VOOZH about

URL: https://pypi.org/project/pytest-datadir/

โ‡ฑ pytest-datadir ยท PyPI


Skip to main content

pytest-datadir 1.8.0

pip install pytest-datadir

Latest release

Released:

pytest plugin for test data directories and files

Navigation

Unverified details

These details have not been verified by PyPI
Project links
Meta
  • License: MIT License (MIT)
  • Author: Gabriel Reis
  • Tags pytest , test , unittest , directory , file
  • Requires: Python >=3.8
  • Provides-Extra: testing , dev

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)
deftest_read_global(shared_datadir):
 contents = (shared_datadir / "hello.txt").read_text()
 assert contents == "Hello World!\n"


deftest_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.

deftest_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.

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

License

MIT.

Project details

Unverified details

These details have not been verified by PyPI
Project links
Meta
  • License: MIT License (MIT)
  • Author: Gabriel Reis
  • Tags pytest , test , unittest , directory , file
  • Requires: Python >=3.8
  • Provides-Extra: testing , dev

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

Filter files by name, interpreter, ABI, and platform.

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

Copy a direct link to the current filters

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.

Supported by

๐Ÿ‘ Image
AWS Cloud computing and Security Sponsor ๐Ÿ‘ Image
Datadog Monitoring ๐Ÿ‘ Image
Depot Continuous Integration ๐Ÿ‘ Image
Fastly CDN ๐Ÿ‘ Image
Google Download Analytics ๐Ÿ‘ Image
Pingdom Monitoring ๐Ÿ‘ Image
Sentry Error logging ๐Ÿ‘ Image
StatusPage Status page