Parse pytest results into structured format.
(self, result: subprocess.CompletedProcess,
total_duration: float, args: argparse.Namespace)
| 178 | return self.parse_test_results(result, total_duration, args) |
| 179 | |
| 180 | def parse_test_results(self, result: subprocess.CompletedProcess, |
| 181 | total_duration: float, args: argparse.Namespace) -> TestSuiteReport: |
| 182 | """Parse pytest results into structured format.""" |
| 183 | |
| 184 | # Try to load JSON report if available |
| 185 | json_file = self.project_root / "test_results.json" |
| 186 | test_results = [] |
| 187 | summary = {"passed": 0, "failed": 0, "skipped": 0, "errors": 0} |
| 188 | |
| 189 | if json_file.exists(): |
| 190 | try: |
| 191 | with open(json_file, 'r') as f: |
| 192 | data = json.load(f) |
| 193 | |
| 194 | for test in data.get('tests', []): |
| 195 | category = self.categorize_test(test['nodeid']) |
| 196 | test_result = TestResult( |
| 197 | name=test['nodeid'], |
| 198 | status=test['outcome'].upper(), |
| 199 | duration=test.get('duration', 0), |
| 200 | category=category, |
| 201 | error_message=test.get('call', {}).get('longrepr') if test['outcome'] == 'failed' else None |
| 202 | ) |
| 203 | test_results.append(test_result) |
| 204 | |
| 205 | summary = data.get('summary', summary) |
| 206 | |
| 207 | except (json.JSONDecodeError, KeyError) as e: |
| 208 | print(f"Warning: Could not parse JSON report: {e}") |
| 209 | |
| 210 | # Performance analysis |
| 211 | perf_summary = self.analyze_performance(test_results) |
| 212 | |
| 213 | return TestSuiteReport( |
| 214 | total_tests=len(test_results), |
| 215 | passed=summary.get('passed', 0), |
| 216 | failed=summary.get('failed', 0), |
| 217 | skipped=summary.get('skipped', 0), |
| 218 | errors=summary.get('error', 0), |
| 219 | total_duration=total_duration, |
| 220 | parallel_workers=args.workers or "auto", |
| 221 | results=test_results, |
| 222 | performance_summary=perf_summary |
| 223 | ) |
| 224 | |
| 225 | def categorize_test(self, test_name: str) -> str: |
| 226 | """Categorize test based on its path and name.""" |
no test coverage detected