pytest-artifacts
Pytest plugin for managing test artifacts
Installation
You can install "pytest-artifacts" from PyPI:
pip install pytest-artifacts
Usage
Attach the artifacts fixture to your pytest test case. The attribute artifacts.dir is a dedicated directory for the test case.
import time
import matplotlib.pyplot as plt
def test_benchmark(artifacts):
times = range(1, 101, 10)
elapsed = []
for t in times:
start_time = time.perf_counter()
time.sleep(t)
end_time = time.perf_counter()
elapsed.append(end_time - start_time)
plt.scatter(times, elapsed)
with artifacts.open('benchmark.png') as f:
plt.savefig(f)
.artifacts/
└── test_benchmark/
└── benchmark.png
The test case directory is named after the test path, function name, and if any, the test parameter ID.
Configure
Configurations may be set in pyproject.toml or pytest.ini. Some options can also be set via CLI (use pytest --help)
| Option | Type | Default | Description |
|---|---|---|---|
artifacts_dir |
str | .artifacts/ |
Directory to store test artifacts. Also settable via the --artifacts-dir CLI option, which takes precedence over the ini setting. |
artifacts_use_subdir_for_parametrize |
bool | false |
When True, parametrized tests get a subdirectory per parameter ID (e.g. .artifacts/test_foo/param_id/). When False, all parameter variants share the same .artifacts/test_foo/ directory and overwrite each other. |
# pyproject.toml
[tool.pytest.ini_options]
artifacts_dir = ".artifacts/"
artifacts_use_subdir_for_parametrize = false
# pytest.ini
[pytest]
artifacts_dir = .artifacts/
artifacts_use_subdir_for_parametrize = false
pytest --artifacts-dir .artifacts/ tests/
Parametrized test layout
@pytest.mark.parametrize("x", [1, 2])
def test_foo(artifacts, x):
with artifacts.open("out.txt", "w") as f:
f.write(str(x))
With artifacts_use_subdir_for_parametrize = false:
.artifacts/
└── test_foo[1]/
└── out.txt
└── test_foo[2]/
└── out.txt
With artifacts_use_subdir_for_parametrize = true:
.artifacts/
└── test_foo/
├── 1/
│ └── out.txt
└── 2/
└── out.txt
Contributing
Contributions are very welcome.
License
Distributed under the terms of the MIT license, "pytest-artifacts" is free and open source software
Issues
If you encounter any problems, please file an issue along with a detailed description.
Metadata
Release files for pytest-artifacts 0.3.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pytest_artifacts-0.3.1.tar.gz | 14.3 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytest_artifacts-0.3.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.8 kB
Release files / pytest_artifacts-0.3.1.tar.gz
| Download URL | pytest_artifacts-0.3.1.tar.gz |
|---|---|
| Size | 14.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d5578f3514589193a05cc4e1d36f7c29a3145c52213801dbd7e1b9048471b948
|
|
BLAKE2b-256 checksum How to use checksums |
0449adbab14141474b31a04537facf6dc3cc06ad920fd7c3392d892c4e2ecb23
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / pytest_artifacts-0.3.1-py3-none-any.whl
| Download URL | pytest_artifacts-0.3.1-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7505a99d3b507b4047f414ae83fbf5f8d8a5459723d666d4edf9288480fde7e0
|
|
BLAKE2b-256 checksum How to use checksums |
0093109a57eccdae5574b733facb5a98efab74ed2d14f9238e6a5875a8f944eb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for pytest-artifacts 0.3.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.