Skip to content

Collector

Test result collector for pytest-agent-digest.

CLASS DESCRIPTION
ReportCollector

Accumulates the TestResult objects while a pytest session runs.

TestResult

Represents a single test outcome captured during a pytest session.

FUNCTION DESCRIPTION
strip_ansi

Remove ANSI escape sequences from text.

Classes

ReportCollector

ReportCollector()

Accumulates the TestResult objects while a pytest session runs.

Wire this into pytest_configure (instantiate) and pytest_runtest_logreport (call add) so the renderer can consume a fully populated collector at the session end.

Initialize with an empty result list.

METHOD DESCRIPTION
add

Classify report and append a TestResult class if it is a call phase.

ATTRIBUTE DESCRIPTION
counts

Return a dict of {outcome: count} with zero-count keys omitted.

TYPE: dict[str, int]

has_failures

Return True if any result is "failed" or "xpassed".

TYPE: bool

Attributes

counts property
counts: dict[str, int]

Return a dict of {outcome: count} with zero-count keys omitted.

RETURNS DESCRIPTION
dict[str, int]

Mapping from the outcome string to the number of results with that outcome.

has_failures property
has_failures: bool

Return True if any result is "failed" or "xpassed".

RETURNS DESCRIPTION
bool

True when there is at least one failure or unexpected pass.

Functions

add
add(report: TestReport) -> None

Classify report and append a TestResult class if it is a call phase.

report.when == "call" reports are stored for normal outcomes. report.when == "setup" reports are stored only when skipped, because @pytest.mark.skip raises a Skipped exception during the setup phase and never produces a call-phase report.

PARAMETER DESCRIPTION
report

The pytest test report to classify and store.

TYPE: TestReport

TestResult dataclass

TestResult(node_id: str, outcome: str, longrepr: str | None, duration: float, skip_reason: str | None)

Represents a single test outcome captured during a pytest session.

ATTRIBUTE DESCRIPTION
node_id

The pytest node ID (e.g. tests/test_foo.py::test_bar).

TYPE: str

outcome

One of "passed", "failed", "skipped", "xfailed", "xpassed".

TYPE: str

longrepr

Formatted traceback or reason string, stripped of ANSI codes. None when not applicable.

TYPE: str | None

duration

Test duration in seconds.

TYPE: float

skip_reason

Human-readable skip reason for skipped tests; None otherwise.

TYPE: str | None

Functions

strip_ansi

strip_ansi(text: str) -> str

Remove ANSI escape sequences from text.

PARAMETER DESCRIPTION
text

The string that may contain ANSI escape sequences.

TYPE: str

RETURNS DESCRIPTION
str

The input string with all ANSI color/style codes removed.