Coverage for pytest_recap/session_stats.py: 0%
11 statements
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-05 17:29 -0600
« prev ^ index » next coverage.py v7.8.0, created at 2025-05-05 17:29 -0600
1"""
2SessionStats: Aggregates and reports test outcome statistics for a session.
3"""
4from collections import Counter
6class SessionStats:
7 """Aggregates test outcome statistics for a session."""
8 def __init__(self, test_results):
9 """
10 Args:
11 test_results (Iterable[TestResult]): List of TestResult objects.
12 """
13 self.counter = Counter(str(getattr(tr, "outcome", tr)).lower() for tr in test_results)
14 self.total = len(test_results)
16 def count(self, outcome):
17 """Return the count for a given outcome (case-insensitive string)."""
18 return self.counter.get(str(outcome).lower(), 0)
20 def as_dict(self):
21 """Return all outcome counts as a dict."""
22 return dict(self.counter)
24 def __str__(self):
25 return f"SessionStats(total={self.total}, {dict(self.counter)})"