pytest plugin for test data directories and files
Project description
pytest-datadir
pytest plugin for manipulating test data directories and files.
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-specifictest_*folders)shared_datadir(for the globaldatafolder)
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
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
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a15faed76cebe87cc91941dd1920a9a38eba56a09c11e9ddf1434d28a0f78eb
|
|
| MD5 |
b484cae6536726231dad90aa92487af3
|
|
| BLAKE2b-256 |
b446db060b291999ca048edd06d6fa9ee95945d088edc38b1172c59eeb46ec45
|
Provenance
The following attestation bundles were made for pytest_datadir-1.8.0.tar.gz:
Publisher:
deploy.yml on gabrielcnr/pytest-datadir
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_datadir-1.8.0.tar.gz -
Subject digest:
7a15faed76cebe87cc91941dd1920a9a38eba56a09c11e9ddf1434d28a0f78eb - Sigstore transparency entry: 330968141
- Sigstore integration time:
-
Permalink:
gabrielcnr/pytest-datadir@cc4dd0a78af32e820969c97848487852c3fa020c -
Branch / Tag:
refs/heads/release-1.8.0 - Owner: https://github.com/gabrielcnr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@cc4dd0a78af32e820969c97848487852c3fa020c -
Trigger Event:
workflow_dispatch
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5c677bc097d907ac71ca418109adc3abe34cf0bddfe6cf78aecfbabd96a15cf0
|
|
| MD5 |
0a62fd932bdf7c3cb612646975049d54
|
|
| BLAKE2b-256 |
8f7a33895863aec26ac3bb5068a73583f935680d6ab6af2a9567d409430c3ee1
|
Provenance
The following attestation bundles were made for pytest_datadir-1.8.0-py3-none-any.whl:
Publisher:
deploy.yml on gabrielcnr/pytest-datadir
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytest_datadir-1.8.0-py3-none-any.whl -
Subject digest:
5c677bc097d907ac71ca418109adc3abe34cf0bddfe6cf78aecfbabd96a15cf0 - Sigstore transparency entry: 330968194
- Sigstore integration time:
-
Permalink:
gabrielcnr/pytest-datadir@cc4dd0a78af32e820969c97848487852c3fa020c -
Branch / Tag:
refs/heads/release-1.8.0 - Owner: https://github.com/gabrielcnr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@cc4dd0a78af32e820969c97848487852c3fa020c -
Trigger Event:
workflow_dispatch
-
Statement type: