Skip to main content

Pytest plugin for managing test artifacts

Project description

pytest-artifacts

PyPI version Python versions See Build Status on GitHub Actions

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.

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_artifacts-0.3.1.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

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

pytest_artifacts-0.3.1-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file pytest_artifacts-0.3.1.tar.gz.

File metadata

  • Download URL: pytest_artifacts-0.3.1.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for pytest_artifacts-0.3.1.tar.gz
Algorithm Hash digest
SHA256 d5578f3514589193a05cc4e1d36f7c29a3145c52213801dbd7e1b9048471b948
MD5 2f42d614678b2ac259c654f114e41d4a
BLAKE2b-256 0449adbab14141474b31a04537facf6dc3cc06ad920fd7c3392d892c4e2ecb23

See more details on using hashes here.

File details

Details for the file pytest_artifacts-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: pytest_artifacts-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for pytest_artifacts-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7505a99d3b507b4047f414ae83fbf5f8d8a5459723d666d4edf9288480fde7e0
MD5 1500f812fad0e01ef742f3c27b7bdedc
BLAKE2b-256 0093109a57eccdae5574b733facb5a98efab74ed2d14f9238e6a5875a8f944eb

See more details on using hashes here.

Supported by

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