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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.1MB
glibcpy 3.10–3.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.fixUpgrade 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`.fixExplicitly 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.fixEnsure 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.fixUpgrade 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.fixUpgrade `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.