Identify tests that have inconsistent results across runs.
(self)
| 404 | return f"Profile {bottleneck_type.lower()} phase to identify specific bottlenecks" |
| 405 | |
| 406 | def identify_flaky_tests(self) -> List[str]: |
| 407 | """Identify tests that have inconsistent results across runs.""" |
| 408 | conn = sqlite3.connect(self.db_path) |
| 409 | |
| 410 | # Find tests with both pass and fail outcomes in recent history |
| 411 | query = ''' |
| 412 | SELECT test_name, COUNT(DISTINCT status) as status_count, |
| 413 | COUNT(*) as total_runs, |
| 414 | SUM(CASE WHEN status = 'failed' THEN 1 ELSE 0 END) as failures |
| 415 | FROM test_runs |
| 416 | WHERE timestamp > datetime('now', '-7 days') |
| 417 | GROUP BY test_name |
| 418 | HAVING status_count > 1 AND total_runs >= 3 |
| 419 | ''' |
| 420 | |
| 421 | cursor = conn.execute(query) |
| 422 | flaky_tests = [] |
| 423 | |
| 424 | for row in cursor.fetchall(): |
| 425 | test_name, status_count, total_runs, failures = row |
| 426 | failure_rate = failures / total_runs |
| 427 | |
| 428 | # Consider a test flaky if it fails 20-80% of the time |
| 429 | if 0.2 <= failure_rate <= 0.8: |
| 430 | flaky_tests.append(test_name) |
| 431 | |
| 432 | conn.close() |
| 433 | return flaky_tests |
| 434 | |
| 435 | def calculate_test_health_score(self, analysis_report: TestAnalysisReport) -> float: |
| 436 | """Calculate overall test suite health score (0-100).""" |