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 globaldata
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
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
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
Algorithm | Hash digest | |
---|---|---|
SHA256 |
15f5228a35d0a3205e4968e75d3b9cca91762424e1eafc21eb637d380a48443e
|
|
MD5 |
7fbcca289428781c63b53378f2d26f0f
|
|
BLAKE2b-256 |
2f167701db071caf7d8f7226b76323de40a09d2a391c7d064cda072d45a87c7b
|
Provenance
The following attestation bundles were made for pytest_datadir-1.7.2.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.7.2.tar.gz
-
Subject digest:
15f5228a35d0a3205e4968e75d3b9cca91762424e1eafc21eb637d380a48443e
- Sigstore transparency entry: 230621508
- Sigstore integration time:
-
Permalink:
gabrielcnr/pytest-datadir@d76d71972c59c24f20aeeb5f1ab0321b12ce6707
-
Branch / Tag:
refs/heads/release-1.7.2
- Owner: https://github.com/gabrielcnr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
deploy.yml@d76d71972c59c24f20aeeb5f1ab0321b12ce6707
-
Trigger Event:
workflow_dispatch
-
Statement type:
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
Algorithm | Hash digest | |
---|---|---|
SHA256 |
8392ba0e9eaf37030e663dcd91cc5123dec99c44300f0c5eac44f35f13f0e086
|
|
MD5 |
5c0187661fcce5405a3bed0ea8bd4648
|
|
BLAKE2b-256 |
d361a06f3406852534e186413c75f544c90251db00fd8eb9625ee3ac239499f3
|
Provenance
The following attestation bundles were made for pytest_datadir-1.7.2-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.7.2-py3-none-any.whl
-
Subject digest:
8392ba0e9eaf37030e663dcd91cc5123dec99c44300f0c5eac44f35f13f0e086
- Sigstore transparency entry: 230621512
- Sigstore integration time:
-
Permalink:
gabrielcnr/pytest-datadir@d76d71972c59c24f20aeeb5f1ab0321b12ce6707
-
Branch / Tag:
refs/heads/release-1.7.2
- Owner: https://github.com/gabrielcnr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com
-
Runner Environment:
github-hosted
-
Publication workflow:
deploy.yml@d76d71972c59c24f20aeeb5f1ab0321b12ce6707
-
Trigger Event:
workflow_dispatch
-
Statement type: