Save test results to JSON file
(self, filename: str = "test_results.json")
| 357 | print(f"\n{RED}{BOLD}SOME TESTS FAILED ❌{RESET}") |
| 358 | |
| 359 | def save_results(self, filename: str = "test_results.json"): |
| 360 | """Save test results to JSON file""" |
| 361 | results = { |
| 362 | 'timestamp': datetime.now().isoformat(), |
| 363 | 'datadir': self.datadir, |
| 364 | 'time_range': f"{self.from_time} to {self.to_time}", |
| 365 | 'suites': {} |
| 366 | } |
| 367 | |
| 368 | for suite in self.suites: |
| 369 | suite_data = { |
| 370 | 'passed': suite.passed, |
| 371 | 'failed': suite.failed, |
| 372 | 'duration': suite.duration, |
| 373 | 'tests': [] |
| 374 | } |
| 375 | |
| 376 | for test in suite.test_cases: |
| 377 | suite_data['tests'].append({ |
| 378 | 'name': test.name, |
| 379 | 'passed': test.passed, |
| 380 | 'duration': test.duration, |
| 381 | 'error': test.error[:500] if test.error else None |
| 382 | }) |
| 383 | |
| 384 | results['suites'][suite.name] = suite_data |
| 385 | |
| 386 | output_path = Path(__file__).parent / filename |
| 387 | with open(output_path, 'w') as f: |
| 388 | json.dump(results, f, indent=2) |
| 389 | |
| 390 | print(f"\nResults saved to: {output_path}") |
| 391 | |
| 392 | |
| 393 | def main(): |