Store test results in database for historical analysis.
(self, results_file: Path)
| 143 | conn.close() |
| 144 | |
| 145 | def store_test_results(self, results_file: Path): |
| 146 | """Store test results in database for historical analysis.""" |
| 147 | if not results_file.exists(): |
| 148 | return |
| 149 | |
| 150 | try: |
| 151 | with open(results_file, 'r') as f: |
| 152 | data = json.load(f) |
| 153 | |
| 154 | conn = sqlite3.connect(self.db_path) |
| 155 | timestamp = time.strftime('%Y-%m-%d %H:%M:%S') |
| 156 | |
| 157 | for test in data.get('tests', []): |
| 158 | conn.execute(''' |
| 159 | INSERT INTO test_runs (timestamp, test_name, status, duration, error_message) |
| 160 | VALUES (?, ?, ?, ?, ?) |
| 161 | ''', ( |
| 162 | timestamp, |
| 163 | test['nodeid'], |
| 164 | test['outcome'], |
| 165 | test.get('duration', 0), |
| 166 | str(test.get('call', {}).get('longrepr', '')) if test['outcome'] == 'failed' else None |
| 167 | )) |
| 168 | |
| 169 | conn.commit() |
| 170 | conn.close() |
| 171 | |
| 172 | except (json.JSONDecodeError, KeyError) as e: |
| 173 | print(f"Warning: Could not store test results: {e}") |
| 174 | |
| 175 | def analyze_failure_patterns(self, results_file: Path) -> List[FailurePattern]: |
| 176 | """Analyze test failures and categorize by patterns.""" |