Analyze test performance and identify bottlenecks.
(self, results: List[TestResult])
| 234 | return "unit" |
| 235 | |
| 236 | def analyze_performance(self, results: List[TestResult]) -> Dict[str, float]: |
| 237 | """Analyze test performance and identify bottlenecks.""" |
| 238 | if not results: |
| 239 | return {} |
| 240 | |
| 241 | durations = [r.duration for r in results] |
| 242 | |
| 243 | # Calculate performance metrics |
| 244 | total_time = sum(durations) |
| 245 | avg_time = total_time / len(durations) if durations else 0 |
| 246 | max_time = max(durations) if durations else 0 |
| 247 | |
| 248 | # Category breakdown |
| 249 | category_times = {} |
| 250 | for result in results: |
| 251 | if result.category not in category_times: |
| 252 | category_times[result.category] = [] |
| 253 | category_times[result.category].append(result.duration) |
| 254 | |
| 255 | perf_summary = { |
| 256 | "total_time": total_time, |
| 257 | "average_time": avg_time, |
| 258 | "max_time": max_time, |
| 259 | "slow_tests_count": len([d for d in durations if d > 5.0]), |
| 260 | } |
| 261 | |
| 262 | # Add category averages |
| 263 | for category, times in category_times.items(): |
| 264 | perf_summary[f"{category}_avg"] = sum(times) / len(times) |
| 265 | |
| 266 | return perf_summary |
| 267 | |
| 268 | def format_report(self, report: TestSuiteReport, format_type: str = "detailed") -> str: |
| 269 | """Format test report for different output types.""" |