Skip to content

Pytest tally

pytest_tally

Tally pytest outcome lines (FAILED/ERROR/SKIPPED/...) into per-kind counts.

Stdlib-only helper: classify each line by its leading whitespace-stripped, lower-cased first token. Unrecognised or malformed elements are routed to the unknown bucket so the sum of all buckets always equals the input length.

tally_outcomes(lines)

Count pytest outcome lines per kind.

Parameters:

Name Type Description Default
lines Iterable[object]

An iterable of outcome lines (typically pytest short-summary lines such as "FAILED tests/..."). Non-string / None / malformed elements are tolerated.

required

Returns:

Type Description
dict[str, int]

A dict with the fixed keys failed/error/skipped/unknown

dict[str, int]

(each always present, initialised to 0). Every input element

dict[str, int]

increments exactly one bucket, so the bucket sum equals the number of

dict[str, int]

elements.

Source code in packages/axm-ingot/src/axm_ingot/pytest_tally.py
Python
def tally_outcomes(lines: Iterable[object]) -> dict[str, int]:
    """Count pytest outcome lines per kind.

    Args:
        lines: An iterable of outcome lines (typically pytest short-summary
            lines such as ``"FAILED tests/..."``). Non-string / ``None`` /
            malformed elements are tolerated.

    Returns:
        A dict with the fixed keys ``failed``/``error``/``skipped``/``unknown``
        (each always present, initialised to ``0``). Every input element
        increments exactly one bucket, so the bucket sum equals the number of
        elements.
    """
    tally: dict[str, int] = {"failed": 0, "error": 0, "skipped": 0, "unknown": 0}
    for line in lines:
        tally[_classify(line)] += 1
    return tally