Skip to content

ketozhang/pytest-artifacts

Repository files navigation

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, pytest.ini, or passed as command line options.

# pyproject.toml
[tool.pytest]
artifacts_dir = .artifacts/
# pytest.ini
[pytest]
artifacts_dir = .artifacts/
pytest --artifacts-dir .artifacts/ tests/

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.

About

Pytest plugin for managing test artifacts

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages