Registry / testing / pytest-harvest

pytest-harvest

JSON →
library1.10.5pypypiunverified

pytest-harvest is a pytest plugin that allows you to store data created during your pytest tests execution and retrieve it at the end of the session. This is particularly useful for applicative benchmarking purposes, collecting custom metrics, or generating reports. The current version is 1.10.5, and it maintains a regular release cadence, often to ensure compatibility with new pytest versions and address bug fixes.

pip install pytest-harvest
INSTALL
IMPORT
SIG · PYTEST-HARVEST
P
pytest-harvest
testingpythonv1.10.5
Install
1.8s avg
Import
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v1.10.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.1MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.8s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

get_session_synthesis_dct
from pytest_harvest import get_session_synthesis_dct
from pytest_harvest import get_session_synthesis_dct

This quickstart demonstrates how to define a custom metric using a fixture, store its value during test execution with `request.node.add_pytest_stats`, and then retrieve all collected data at the end of the session using `get_session_synthesis_dct` within a `pytest_sessionfinish` hook. Run `pytest -s` from your terminal to see the results printed.

import pytest from pytest_harvest import get_session_synthesis_dct # conftest.py @pytest.fixture def custom_metric_value(): return 'important_data' def pytest_sessionfinish(session): print("\n--- Session Synthesis Results ---") results = get_session_synthesis_dct(session) for test_id, res in results.items(): custom = getattr(res, 'custom_metric_value', 'N/A') print(f"Test: {test_id}, Outcome: {res.outcome}, Custom: {custom}") print("---------------------------------") # test_example.py def test_success(request, custom_metric_value): request.node.add_pytest_stats(custom_metric_value=custom_metric_value) assert True def test_failure(request, custom_metric_value): request.node.add_pytest_stats(custom_metric_value=custom_metric_value + '_failed') pytest.fail("Intentionally failed test") # To run these tests and see the output: # 1. Save the conftest.py content as 'conftest.py' in your test directory. # 2. Save the test_example.py content as 'test_example.py' in the same directory. # 3. Run from your terminal: pytest -s
Debug
Known issues
breakingpytest-harvest versions prior to 1.10.5 are incompatible with pytest>=8.1 due to changes in pytest internals, leading to `AttributeError` or signature mismatches.
fix
Upgrade to pytest-harvest>=1.10.5 to ensure compatibility with pytest 8.1 and later: `pip install --upgrade pytest-harvest`.
affects: <1.10.5
gotchaUsing result fixtures like `module_results_df` or `session_results_df` without `pandas` installed will raise an `ImportError`. `pytest-harvest` uses lazy loading for `pandas`.
fix
Explicitly install pandas if you intend to use DataFrame result fixtures: `pip install pandas`.
affects: All versions
gotcha`pytest-xdist` integration, especially with older `pytest` versions or `python 3.5`, had known issues with result consolidation or `pathlib` object handling.
fix
Ensure you are using `pytest-harvest>=1.10.4` and the latest compatible `pytest-xdist` version for robust distributed testing result collection.
affects: <1.10.3 (for xdist hook), <1.10.4 (for python 3.5 xdist bugfix)
gotchaTest IDs containing `::` were not properly handled by `get_session_synthesis_dct` and related fixtures, leading to incomplete or incorrect results.
fix
Upgrade to `pytest-harvest>=1.10.1` to correctly parse test IDs with `::` delimiters.
affects: <1.10.1
gotchaWhen using `pytest-cases` with `lazy_value` parameters, `module_results_df` in `pytest < 5.3` might wrongly insert values as integers instead of objects.
fix
Upgrade `pytest-harvest` to `>=1.10.0` and `pytest-cases` to `>=2.3.0` to resolve this specific interaction issue.
affects: <1.10.0 with pytest-cases and pytest < 5.3
Upgrade
Version history
1.10.5latest on PyPI · released Mar 16, 2024
Audit
Dependencies
pytestrequiredCore dependency for a pytest plugin.
pandasoptionalRequired if you wish to retrieve test results as pandas DataFrames (e.g., via `module_results_df`, `session_results_df`). It is lazy-loaded.
pytest-xdistoptionalEnables distributed test execution with `pytest-harvest`'s result consolidation features.
pytest-casesoptionalMentioned as compatible, especially concerning `lazy_value` parameters. Not strictly required for basic `pytest-harvest` usage.
Agent activity
11 hits · last 30 days
node
10
Amazon
1
Resources
pytest-harvest — pip install pytest-harvest · libregistry