test-reporting 4.1.1__tar.gz → 4.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {test_reporting-4.1.1 → test_reporting-4.2.0}/PKG-INFO +11 -7
- {test_reporting-4.1.1 → test_reporting-4.2.0}/README.md +10 -6
- {test_reporting-4.1.1 → test_reporting-4.2.0}/reporting/cli.py +20 -3
- {test_reporting-4.1.1 → test_reporting-4.2.0}/reporting/exporters/pdf_exporter.py +5 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/reporting/exporters/pptx_exporter.py +5 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/reporting/exporters/xlsx_exporter.py +5 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/reporting/monthly_report.py +95 -11
- test_reporting-4.2.0/reporting/monthly_ui.py +127 -0
- test_reporting-4.2.0/reporting/run_source.py +78 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/setup.py +1 -1
- {test_reporting-4.1.1 → test_reporting-4.2.0}/test_reporting.egg-info/PKG-INFO +11 -7
- {test_reporting-4.1.1 → test_reporting-4.2.0}/test_reporting.egg-info/SOURCES.txt +4 -1
- test_reporting-4.2.0/tests/test_published_monthly_report.py +139 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/LICENSE +0 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/reporting/__init__.py +0 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/reporting/classifier.py +0 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/reporting/config.py +0 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/reporting/exporters/__init__.py +0 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/reporting/plugin.py +0 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/reporting/publisher.py +0 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/reporting/storage.py +0 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/reporting/templates/index.html +0 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/reporting/templates/project.html +0 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/reporting/templates/run.html +0 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/setup.cfg +0 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/test_reporting.egg-info/dependency_links.txt +0 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/test_reporting.egg-info/entry_points.txt +0 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/test_reporting.egg-info/requires.txt +0 -0
- {test_reporting-4.1.1 → test_reporting-4.2.0}/test_reporting.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: test-reporting
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.2.0
|
|
4
4
|
Summary: Multi-project test reporting dashboard — collect results locally or push to S3
|
|
5
5
|
Home-page: https://github.com/amahdy77/test-reporting.git
|
|
6
6
|
Author: Ashfaqur Mahdy
|
|
@@ -261,6 +261,7 @@ dashboard_max_runs_per_suite = 50 # Run history per suite (default: 50)
|
|
|
261
261
|
| `test-report cleanup` | Delete old runs from local SQLite |
|
|
262
262
|
| `test-report cleanup-artifacts` | Delete old screenshots and traces (preserves data) |
|
|
263
263
|
| `test-report monthly-report` | Generate monthly test report (PPTX/XLSX/PDF) |
|
|
264
|
+
| `test-report monthly-ui` | Open local project and date picker for reports |
|
|
264
265
|
|
|
265
266
|
### Cleaning up old data
|
|
266
267
|
|
|
@@ -319,19 +320,22 @@ retention_days = 90 # Keep 90 days of artifacts and data
|
|
|
319
320
|
|
|
320
321
|
## Monthly Reports
|
|
321
322
|
|
|
322
|
-
Generate
|
|
323
|
+
Generate a report for one project from its published run history. The report reader supports the same local or S3 store used by `test-report publish`; it does not need a copied SQLite database.
|
|
323
324
|
|
|
324
325
|
### Quick Start
|
|
325
326
|
|
|
326
327
|
```bash
|
|
327
|
-
# Install with report dependencies
|
|
328
|
+
# Install with report dependencies and S3 support
|
|
328
329
|
pip install test-reporting[s3,reports]
|
|
329
330
|
|
|
330
|
-
#
|
|
331
|
-
test-report monthly-
|
|
331
|
+
# Open the local project and date picker
|
|
332
|
+
test-report monthly-ui --config reporting.ini
|
|
333
|
+
|
|
334
|
+
# Generate without the UI (defaults to the last 30 days)
|
|
335
|
+
test-report monthly-report --project "My Project" --format pptx,xlsx,pdf
|
|
332
336
|
|
|
333
337
|
# Custom date range
|
|
334
|
-
test-report monthly-report --start 2026-08-01 --end 2026-08-31 --format xlsx
|
|
338
|
+
test-report monthly-report --project "My Project" --start 2026-08-01 --end 2026-08-31 --format xlsx
|
|
335
339
|
|
|
336
340
|
# Specific project
|
|
337
341
|
test-report monthly-report --project "My Project" --format pptx
|
|
@@ -346,7 +350,7 @@ test-report monthly-report --project "My Project" --format pptx
|
|
|
346
350
|
- 📁 File health report
|
|
347
351
|
- 💡 Actionable recommendations
|
|
348
352
|
|
|
349
|
-
**See [
|
|
353
|
+
**See [REPORT_GENERATOR.md](REPORT_GENERATOR.md) for setup and metric definitions.**
|
|
350
354
|
|
|
351
355
|
---
|
|
352
356
|
|
|
@@ -220,6 +220,7 @@ dashboard_max_runs_per_suite = 50 # Run history per suite (default: 50)
|
|
|
220
220
|
| `test-report cleanup` | Delete old runs from local SQLite |
|
|
221
221
|
| `test-report cleanup-artifacts` | Delete old screenshots and traces (preserves data) |
|
|
222
222
|
| `test-report monthly-report` | Generate monthly test report (PPTX/XLSX/PDF) |
|
|
223
|
+
| `test-report monthly-ui` | Open local project and date picker for reports |
|
|
223
224
|
|
|
224
225
|
### Cleaning up old data
|
|
225
226
|
|
|
@@ -278,19 +279,22 @@ retention_days = 90 # Keep 90 days of artifacts and data
|
|
|
278
279
|
|
|
279
280
|
## Monthly Reports
|
|
280
281
|
|
|
281
|
-
Generate
|
|
282
|
+
Generate a report for one project from its published run history. The report reader supports the same local or S3 store used by `test-report publish`; it does not need a copied SQLite database.
|
|
282
283
|
|
|
283
284
|
### Quick Start
|
|
284
285
|
|
|
285
286
|
```bash
|
|
286
|
-
# Install with report dependencies
|
|
287
|
+
# Install with report dependencies and S3 support
|
|
287
288
|
pip install test-reporting[s3,reports]
|
|
288
289
|
|
|
289
|
-
#
|
|
290
|
-
test-report monthly-
|
|
290
|
+
# Open the local project and date picker
|
|
291
|
+
test-report monthly-ui --config reporting.ini
|
|
292
|
+
|
|
293
|
+
# Generate without the UI (defaults to the last 30 days)
|
|
294
|
+
test-report monthly-report --project "My Project" --format pptx,xlsx,pdf
|
|
291
295
|
|
|
292
296
|
# Custom date range
|
|
293
|
-
test-report monthly-report --start 2026-08-01 --end 2026-08-31 --format xlsx
|
|
297
|
+
test-report monthly-report --project "My Project" --start 2026-08-01 --end 2026-08-31 --format xlsx
|
|
294
298
|
|
|
295
299
|
# Specific project
|
|
296
300
|
test-report monthly-report --project "My Project" --format pptx
|
|
@@ -305,7 +309,7 @@ test-report monthly-report --project "My Project" --format pptx
|
|
|
305
309
|
- 📁 File health report
|
|
306
310
|
- 💡 Actionable recommendations
|
|
307
311
|
|
|
308
|
-
**See [
|
|
312
|
+
**See [REPORT_GENERATOR.md](REPORT_GENERATOR.md) for setup and metric definitions.**
|
|
309
313
|
|
|
310
314
|
---
|
|
311
315
|
|
|
@@ -361,7 +361,9 @@ def monthly_report():
|
|
|
361
361
|
parser = argparse.ArgumentParser(description='Generate monthly test report')
|
|
362
362
|
parser.add_argument('--start', help='Start date (YYYY-MM-DD)')
|
|
363
363
|
parser.add_argument('--end', help='End date (YYYY-MM-DD)')
|
|
364
|
-
parser.add_argument('--project', help='
|
|
364
|
+
parser.add_argument('--project', required=True, help='One published project name')
|
|
365
|
+
parser.add_argument('--source', choices=['published', 'sqlite'], default='published',
|
|
366
|
+
help='Read published run JSON (default) or legacy local SQLite')
|
|
365
367
|
parser.add_argument('--format', '--formats', dest='formats', default='pptx',
|
|
366
368
|
help='Output format(s): pptx, xlsx, pdf (comma-separated)')
|
|
367
369
|
parser.add_argument('--output', help='Output directory (default: ./reports)')
|
|
@@ -382,7 +384,7 @@ def monthly_report():
|
|
|
382
384
|
if args.start:
|
|
383
385
|
start_date = args.start
|
|
384
386
|
else:
|
|
385
|
-
start = datetime.now() - timedelta(days=
|
|
387
|
+
start = datetime.now() - timedelta(days=29)
|
|
386
388
|
start_date = start.strftime('%Y-%m-%d')
|
|
387
389
|
|
|
388
390
|
# Parse formats
|
|
@@ -400,7 +402,7 @@ def monthly_report():
|
|
|
400
402
|
print(f"[Monthly Report] Formats: {', '.join(formats)}")
|
|
401
403
|
|
|
402
404
|
# Generate report
|
|
403
|
-
generator = MonthlyReportGenerator(config)
|
|
405
|
+
generator = MonthlyReportGenerator(config, source=args.source)
|
|
404
406
|
files = generator.generate(
|
|
405
407
|
start_date=start_date,
|
|
406
408
|
end_date=end_date,
|
|
@@ -415,6 +417,20 @@ def monthly_report():
|
|
|
415
417
|
print(f" ✓ {f}")
|
|
416
418
|
|
|
417
419
|
|
|
420
|
+
def monthly_ui():
|
|
421
|
+
"""Open the local report generator with project and date selectors."""
|
|
422
|
+
import argparse
|
|
423
|
+
from .monthly_ui import serve
|
|
424
|
+
|
|
425
|
+
parser = argparse.ArgumentParser(description='Local monthly report generator')
|
|
426
|
+
parser.add_argument('--config', default='reporting.ini')
|
|
427
|
+
parser.add_argument('--port', type=int, default=8766)
|
|
428
|
+
parser.add_argument('--no-browser', action='store_true')
|
|
429
|
+
args = parser.parse_args(sys.argv[2:])
|
|
430
|
+
serve(ReportingConfig(config_file=args.config), port=args.port,
|
|
431
|
+
open_browser=not args.no_browser)
|
|
432
|
+
|
|
433
|
+
|
|
418
434
|
def main():
|
|
419
435
|
"""Main CLI entry point."""
|
|
420
436
|
commands = {
|
|
@@ -427,6 +443,7 @@ def main():
|
|
|
427
443
|
'cleanup': (cleanup_old_data, 'Clean up old data from local SQLite'),
|
|
428
444
|
'cleanup-artifacts': (cleanup_artifacts, 'Clean up old screenshots and traces'),
|
|
429
445
|
'monthly-report': (monthly_report, 'Generate monthly test report (PPTX/XLSX/PDF)'),
|
|
446
|
+
'monthly-ui': (monthly_ui, 'Open local project and date picker for reports'),
|
|
430
447
|
}
|
|
431
448
|
|
|
432
449
|
if len(sys.argv) < 2 or sys.argv[1] not in commands:
|
|
@@ -195,6 +195,11 @@ class PDFExporter:
|
|
|
195
195
|
['Functional Pass Rate', f"{summary['functional_pass_rate']}%"],
|
|
196
196
|
['Total Passed', str(summary['total_passed'])],
|
|
197
197
|
['Total Failed', str(summary['total_failed'])],
|
|
198
|
+
['Total Skipped', str(summary.get('total_skipped', 0))],
|
|
199
|
+
['Detailed Records', f"{summary.get('detail_count', 0)} ({'complete' if summary.get('detail_complete') else 'incomplete'})"],
|
|
200
|
+
['Previous Period Runs', str(summary.get('previous_runs', 0))],
|
|
201
|
+
['Previous Pass Rate', f"{summary['previous_pass_rate']}%" if summary.get('previous_pass_rate') is not None else 'No data'],
|
|
202
|
+
['Pass Rate Change', f"{summary['pass_rate_change']:+.1f} points" if summary.get('pass_rate_change') is not None else 'No data'],
|
|
198
203
|
['Trend', summary['trend']],
|
|
199
204
|
['Avg Duration (per run)', f"{summary['avg_duration']}s"],
|
|
200
205
|
]
|
|
@@ -185,6 +185,11 @@ class PowerPointExporter:
|
|
|
185
185
|
# Additional metrics
|
|
186
186
|
additional = [
|
|
187
187
|
f"Passed: {summary['total_passed']} | Failed: {summary['total_failed']}",
|
|
188
|
+
f"Skipped: {summary.get('total_skipped', 0)}",
|
|
189
|
+
(f"Detailed records: {summary.get('detail_count', 0)}"
|
|
190
|
+
+ (' (complete)' if summary.get('detail_complete') else ' (incomplete)')),
|
|
191
|
+
(f"Previous period: {summary['previous_pass_rate']}% ({summary['pass_rate_change']:+.1f} points)"
|
|
192
|
+
if summary.get('previous_pass_rate') is not None else 'Previous period: no data'),
|
|
188
193
|
f"Trend: {summary['trend']}",
|
|
189
194
|
f"Avg Duration: {summary['avg_duration']}s per run"
|
|
190
195
|
]
|
|
@@ -109,6 +109,11 @@ class ExcelExporter:
|
|
|
109
109
|
('Functional Pass Rate', f"{summary['functional_pass_rate']}%", self._get_health_fill(summary['functional_pass_rate'])),
|
|
110
110
|
('Total Passed', summary['total_passed'], PatternFill(start_color=self.colors['green'], fill_type='solid')),
|
|
111
111
|
('Total Failed', summary['total_failed'], PatternFill(start_color=self.colors['red'], fill_type='solid')),
|
|
112
|
+
('Total Skipped', summary.get('total_skipped', 0), None),
|
|
113
|
+
('Detailed Records', f"{summary.get('detail_count', 0)} ({'complete' if summary.get('detail_complete') else 'incomplete'})", None),
|
|
114
|
+
('Previous Period Runs', summary.get('previous_runs', 0), None),
|
|
115
|
+
('Previous Pass Rate', f"{summary['previous_pass_rate']}%" if summary.get('previous_pass_rate') is not None else 'No data', None),
|
|
116
|
+
('Pass Rate Change', f"{summary['pass_rate_change']:+.1f} points" if summary.get('pass_rate_change') is not None else 'No data', None),
|
|
112
117
|
('Trend', summary['trend'], None),
|
|
113
118
|
('Avg Duration (per run)', f"{summary['avg_duration']}s", None),
|
|
114
119
|
]
|
|
@@ -3,21 +3,24 @@ Monthly Report Generator
|
|
|
3
3
|
Generates comprehensive monthly test reports in multiple formats (PPTX, XLSX, PDF).
|
|
4
4
|
"""
|
|
5
5
|
import json
|
|
6
|
-
from datetime import datetime, timedelta
|
|
6
|
+
from datetime import date, datetime, timedelta
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
from typing import Dict, Any, List, Optional
|
|
9
9
|
from collections import defaultdict
|
|
10
10
|
|
|
11
11
|
from .config import ReportingConfig
|
|
12
12
|
from .storage import TestResultStorage
|
|
13
|
+
from .run_source import PublishedRunSource
|
|
13
14
|
|
|
14
15
|
|
|
15
16
|
class MonthlyReportGenerator:
|
|
16
17
|
"""Generates monthly test reports with metrics and visualizations."""
|
|
17
18
|
|
|
18
|
-
def __init__(self, config: Optional[ReportingConfig] = None):
|
|
19
|
+
def __init__(self, config: Optional[ReportingConfig] = None, source='published', run_source=None):
|
|
19
20
|
self.config = config or ReportingConfig()
|
|
20
|
-
self.
|
|
21
|
+
self.source = source
|
|
22
|
+
self.run_source = run_source or PublishedRunSource(self.config)
|
|
23
|
+
self.storage = TestResultStorage(config=self.config) if source == 'sqlite' else None
|
|
21
24
|
|
|
22
25
|
def generate(
|
|
23
26
|
self,
|
|
@@ -46,7 +49,17 @@ class MonthlyReportGenerator:
|
|
|
46
49
|
Returns:
|
|
47
50
|
List of generated file paths
|
|
48
51
|
"""
|
|
52
|
+
if self.source not in ('published', 'sqlite'):
|
|
53
|
+
raise ValueError(f'Unknown report source: {self.source}')
|
|
54
|
+
start = date.fromisoformat(start_date)
|
|
55
|
+
end = date.fromisoformat(end_date)
|
|
56
|
+
if start > end:
|
|
57
|
+
raise ValueError('Start date must be on or before end date')
|
|
58
|
+
if not project:
|
|
59
|
+
raise ValueError('Select one project for the report')
|
|
49
60
|
formats = formats or ['pptx']
|
|
61
|
+
if not set(formats) <= {'pptx', 'xlsx', 'pdf'}:
|
|
62
|
+
raise ValueError('Formats must be pptx, xlsx, or pdf')
|
|
50
63
|
sections = sections or {}
|
|
51
64
|
output_dir = output_dir or Path.cwd() / 'reports'
|
|
52
65
|
output_dir.mkdir(parents=True, exist_ok=True)
|
|
@@ -57,7 +70,20 @@ class MonthlyReportGenerator:
|
|
|
57
70
|
|
|
58
71
|
# Collect and calculate metrics
|
|
59
72
|
data = self.collect_data(start_date, end_date, project)
|
|
73
|
+
if not data['runs']:
|
|
74
|
+
raise ValueError(f'No runs found for {project} from {start_date} to {end_date}')
|
|
60
75
|
metrics = self.calculate_metrics(data, top_n)
|
|
76
|
+
period_days = (end - start).days + 1
|
|
77
|
+
previous_end = start - timedelta(days=1)
|
|
78
|
+
previous_start = previous_end - timedelta(days=period_days - 1)
|
|
79
|
+
previous = self.collect_data(previous_start.isoformat(), previous_end.isoformat(), project)
|
|
80
|
+
previous_total = sum(r.get('total_tests', 0) for r in previous['runs'])
|
|
81
|
+
previous_passed = sum(r.get('passed', 0) for r in previous['runs'])
|
|
82
|
+
summary = metrics['summary']
|
|
83
|
+
summary['previous_runs'] = len(previous['runs'])
|
|
84
|
+
summary['previous_pass_rate'] = round(previous_passed / previous_total * 100, 1) if previous_total else None
|
|
85
|
+
summary['pass_rate_change'] = (round(summary['pass_rate'] - summary['previous_pass_rate'], 1)
|
|
86
|
+
if summary['previous_pass_rate'] is not None else None)
|
|
61
87
|
|
|
62
88
|
# Generate report metadata
|
|
63
89
|
report_meta = {
|
|
@@ -103,11 +129,46 @@ class MonthlyReportGenerator:
|
|
|
103
129
|
|
|
104
130
|
def _make_filename(self, start_date: str, end_date: str, project: Optional[str], ext: str) -> str:
|
|
105
131
|
"""Generate filename for report."""
|
|
106
|
-
|
|
132
|
+
import re
|
|
133
|
+
project_part = re.sub(r'[^A-Za-z0-9._-]+', '-', project).strip('.-') + '_' if project else ''
|
|
107
134
|
return f"monthly-report_{project_part}{start_date}_to_{end_date}.{ext}"
|
|
108
135
|
|
|
109
136
|
def collect_data(self, start_date: str, end_date: str, project: Optional[str] = None) -> Dict[str, Any]:
|
|
110
|
-
"""Collect test run
|
|
137
|
+
"""Collect test results from published run files or legacy SQLite."""
|
|
138
|
+
if self.source == 'published':
|
|
139
|
+
runs = []
|
|
140
|
+
results = []
|
|
141
|
+
for index, run in enumerate(self.run_source.runs(project, start_date, end_date), 1):
|
|
142
|
+
runs.append({**run, 'id': index})
|
|
143
|
+
failed_details = {
|
|
144
|
+
(t.get('test_name'), t.get('file_name')): t
|
|
145
|
+
for t in run.get('failed_tests', [])
|
|
146
|
+
}
|
|
147
|
+
tests = run.get('all_tests')
|
|
148
|
+
if tests is None:
|
|
149
|
+
tests = run.get('passed_tests', []) + run.get('failed_tests', [])
|
|
150
|
+
for test in tests:
|
|
151
|
+
status = test.get('status')
|
|
152
|
+
if not status:
|
|
153
|
+
status = 'failed' if (test.get('test_name'), test.get('file_name')) in failed_details else 'passed'
|
|
154
|
+
detail = failed_details.get((test.get('test_name'), test.get('file_name')), {})
|
|
155
|
+
results.append({
|
|
156
|
+
'run_id': index,
|
|
157
|
+
'test_name': test.get('test_name'),
|
|
158
|
+
'file_name': test.get('file_name'),
|
|
159
|
+
'status': status,
|
|
160
|
+
'duration_seconds': test.get('duration_seconds') or 0,
|
|
161
|
+
'failure_type': test.get('failure_type') or detail.get('failure_type'),
|
|
162
|
+
'is_soft_fail': detail.get('is_soft_fail', False),
|
|
163
|
+
'created_at': run.get('timestamp', ''),
|
|
164
|
+
})
|
|
165
|
+
runs.sort(key=lambda r: r.get('timestamp', ''))
|
|
166
|
+
return {'runs': runs, 'results': results, 'start_date': start_date,
|
|
167
|
+
'end_date': end_date, 'project': project}
|
|
168
|
+
return self._collect_sqlite_data(start_date, end_date, project)
|
|
169
|
+
|
|
170
|
+
def _collect_sqlite_data(self, start_date, end_date, project):
|
|
171
|
+
"""Read the legacy local database when explicitly requested."""
|
|
111
172
|
import sqlite3
|
|
112
173
|
|
|
113
174
|
conn = sqlite3.connect(self.storage.db_path)
|
|
@@ -200,6 +261,16 @@ class MonthlyReportGenerator:
|
|
|
200
261
|
recommendations = self._generate_recommendations(
|
|
201
262
|
summary, failure_hotspots, flaky_tests, slowest_tests
|
|
202
263
|
)
|
|
264
|
+
|
|
265
|
+
# Older published files may only contain selected test details. Never
|
|
266
|
+
# present test-level rates or trends as complete when records are missing.
|
|
267
|
+
if not summary['detail_complete']:
|
|
268
|
+
flaky_tests = []
|
|
269
|
+
slowest_tests = []
|
|
270
|
+
performance_regressions = []
|
|
271
|
+
file_health = []
|
|
272
|
+
recommendations = self._generate_recommendations(summary, failure_hotspots, [], [])
|
|
273
|
+
recommendations.insert(0, 'Detailed test history is incomplete for this period; test-level analysis is omitted.')
|
|
203
274
|
|
|
204
275
|
return {
|
|
205
276
|
'summary': summary,
|
|
@@ -239,6 +310,7 @@ class MonthlyReportGenerator:
|
|
|
239
310
|
total_tests = sum(r.get('total_tests', 0) for r in runs)
|
|
240
311
|
total_passed = sum(r.get('passed', 0) for r in runs)
|
|
241
312
|
total_failed = sum(r.get('failed', 0) for r in runs)
|
|
313
|
+
total_skipped = sum(r.get('skipped', 0) for r in runs)
|
|
242
314
|
|
|
243
315
|
pass_rate = round((total_passed / total_tests * 100) if total_tests > 0 else 0, 1)
|
|
244
316
|
|
|
@@ -248,18 +320,23 @@ class MonthlyReportGenerator:
|
|
|
248
320
|
if r.get('status') == 'passed' or r.get('is_soft_fail')
|
|
249
321
|
)
|
|
250
322
|
functional_total = len([r for r in results if r.get('status') in ['passed', 'failed']])
|
|
323
|
+
detail_complete = functional_total >= total_passed + total_failed
|
|
251
324
|
functional_pass_rate = round(
|
|
252
|
-
(functional_passed / functional_total * 100) if functional_total > 0 else
|
|
325
|
+
(functional_passed / functional_total * 100) if detail_complete and functional_total > 0 else pass_rate, 1
|
|
253
326
|
)
|
|
254
327
|
|
|
255
328
|
# Health score based on functional pass rate
|
|
256
329
|
health_score = round(functional_pass_rate)
|
|
257
330
|
|
|
258
|
-
# Calculate trend
|
|
331
|
+
# Calculate trend from weighted test executions in each half.
|
|
259
332
|
mid_point = len(runs) // 2
|
|
260
333
|
if mid_point > 0:
|
|
261
|
-
|
|
262
|
-
|
|
334
|
+
first_total = sum(r.get('total_tests', 0) for r in runs[:mid_point])
|
|
335
|
+
second_total = sum(r.get('total_tests', 0) for r in runs[mid_point:])
|
|
336
|
+
first_half_rate = (sum(r.get('passed', 0) for r in runs[:mid_point]) / first_total * 100
|
|
337
|
+
if first_total else 0)
|
|
338
|
+
second_half_rate = (sum(r.get('passed', 0) for r in runs[mid_point:]) / second_total * 100
|
|
339
|
+
if second_total else 0)
|
|
263
340
|
trend_diff = second_half_rate - first_half_rate
|
|
264
341
|
trend = f"{'+' if trend_diff >= 0 else ''}{trend_diff:.1f}%"
|
|
265
342
|
else:
|
|
@@ -271,6 +348,9 @@ class MonthlyReportGenerator:
|
|
|
271
348
|
'total_tests': total_tests,
|
|
272
349
|
'total_passed': total_passed,
|
|
273
350
|
'total_failed': total_failed,
|
|
351
|
+
'total_skipped': total_skipped,
|
|
352
|
+
'detail_count': len(results),
|
|
353
|
+
'detail_complete': detail_complete,
|
|
274
354
|
'pass_rate': pass_rate,
|
|
275
355
|
'functional_pass_rate': functional_pass_rate,
|
|
276
356
|
'trend': trend,
|
|
@@ -429,8 +509,12 @@ class MonthlyReportGenerator:
|
|
|
429
509
|
return []
|
|
430
510
|
|
|
431
511
|
# Split into recent (last 7 days) and historical (7-30 days ago)
|
|
432
|
-
|
|
433
|
-
|
|
512
|
+
period_end = max((r.get('timestamp', '')[:10] for r in runs), default='')
|
|
513
|
+
if not period_end:
|
|
514
|
+
return []
|
|
515
|
+
report_end = date.fromisoformat(period_end)
|
|
516
|
+
cutoff_recent = (report_end - timedelta(days=7)).isoformat()
|
|
517
|
+
cutoff_historical = (report_end - timedelta(days=30)).isoformat()
|
|
434
518
|
|
|
435
519
|
recent_durations = defaultdict(list)
|
|
436
520
|
historical_durations = defaultdict(list)
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"""Loopback-only UI for generating one project's report from published runs."""
|
|
2
|
+
|
|
3
|
+
import html
|
|
4
|
+
import io
|
|
5
|
+
import tempfile
|
|
6
|
+
import webbrowser
|
|
7
|
+
import zipfile
|
|
8
|
+
from datetime import date, timedelta
|
|
9
|
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from urllib.parse import parse_qs
|
|
12
|
+
|
|
13
|
+
from .monthly_report import MonthlyReportGenerator
|
|
14
|
+
from .run_source import PublishedRunSource
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _page(projects, error=''):
|
|
18
|
+
today = date.today()
|
|
19
|
+
start = today - timedelta(days=29)
|
|
20
|
+
options = ''.join(
|
|
21
|
+
f'<option value="{html.escape(p, quote=True)}">{html.escape(p)}</option>'
|
|
22
|
+
for p in projects
|
|
23
|
+
)
|
|
24
|
+
notice = f'<p class="error">{html.escape(error)}</p>' if error else ''
|
|
25
|
+
return f'''<!doctype html>
|
|
26
|
+
<html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
|
27
|
+
<title>Test report generator</title><style>
|
|
28
|
+
body {{font:16px system-ui,sans-serif;background:#f5f7fb;color:#1e293b;margin:0}}
|
|
29
|
+
main {{max-width:620px;margin:7vh auto;background:white;padding:2rem;border-radius:14px;box-shadow:0 8px 30px #17255415}}
|
|
30
|
+
h1 {{margin-top:0}} label {{display:block;font-weight:600;margin-top:1rem}}
|
|
31
|
+
input,select,button {{font:inherit;padding:.7rem;border:1px solid #aab6c6;border-radius:7px;box-sizing:border-box}}
|
|
32
|
+
input,select {{width:100%}} .dates {{display:grid;grid-template-columns:1fr 1fr;gap:1rem}}
|
|
33
|
+
.formats label {{display:inline-block;font-weight:400;margin-right:1rem}} .formats input {{width:auto}}
|
|
34
|
+
button {{margin-top:1.5rem;background:#1d4ed8;color:white;border:0;cursor:pointer}}
|
|
35
|
+
.error {{color:#b91c1c}} small {{color:#64748b}}
|
|
36
|
+
</style></head><body><main><h1>Test report generator</h1>
|
|
37
|
+
<p>Select one project and a date range. Reports are generated from its published run history.</p>
|
|
38
|
+
{notice}
|
|
39
|
+
<form method="post" action="/generate">
|
|
40
|
+
<label for="project">Project</label><select id="project" name="project" required>{options}</select>
|
|
41
|
+
<div class="dates"><div><label for="start">Start date</label><input id="start" name="start" type="date" value="{start.isoformat()}" required></div>
|
|
42
|
+
<div><label for="end">End date</label><input id="end" name="end" type="date" value="{today.isoformat()}" required></div></div>
|
|
43
|
+
<label>Formats</label><div class="formats">
|
|
44
|
+
<label><input type="checkbox" name="format" value="pdf" checked> PDF</label>
|
|
45
|
+
<label><input type="checkbox" name="format" value="pptx" checked> PowerPoint</label>
|
|
46
|
+
<label><input type="checkbox" name="format" value="xlsx" checked> Excel</label></div>
|
|
47
|
+
<button type="submit" onclick="this.textContent='Generating…';">Generate and download</button></form>
|
|
48
|
+
<p><small>Runs stay in S3. The generated files are downloaded to your computer.</small></p>
|
|
49
|
+
</main></body></html>'''.encode('utf-8')
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def make_handler(config, run_source=None):
|
|
53
|
+
source = run_source or PublishedRunSource(config)
|
|
54
|
+
|
|
55
|
+
class Handler(BaseHTTPRequestHandler):
|
|
56
|
+
def _send(self, status, body, content_type):
|
|
57
|
+
self.send_response(status)
|
|
58
|
+
self.send_header('Content-Type', content_type)
|
|
59
|
+
self.send_header('Content-Length', str(len(body)))
|
|
60
|
+
self.send_header('X-Content-Type-Options', 'nosniff')
|
|
61
|
+
self.end_headers()
|
|
62
|
+
self.wfile.write(body)
|
|
63
|
+
|
|
64
|
+
def do_GET(self):
|
|
65
|
+
if self.path != '/':
|
|
66
|
+
self._send(404, b'Not found', 'text/plain; charset=utf-8')
|
|
67
|
+
return
|
|
68
|
+
try:
|
|
69
|
+
self._send(200, _page(source.projects()), 'text/html; charset=utf-8')
|
|
70
|
+
except Exception as exc:
|
|
71
|
+
self._send(500, _page([], str(exc)), 'text/html; charset=utf-8')
|
|
72
|
+
|
|
73
|
+
def do_POST(self):
|
|
74
|
+
if self.path != '/generate':
|
|
75
|
+
self._send(404, b'Not found', 'text/plain; charset=utf-8')
|
|
76
|
+
return
|
|
77
|
+
try:
|
|
78
|
+
length = int(self.headers.get('Content-Length', '0'))
|
|
79
|
+
if length > 8192:
|
|
80
|
+
raise ValueError('Form is too large')
|
|
81
|
+
form = parse_qs(self.rfile.read(length).decode('utf-8'))
|
|
82
|
+
project = form.get('project', [''])[0]
|
|
83
|
+
formats = form.get('format', [])
|
|
84
|
+
if project not in source.projects():
|
|
85
|
+
raise ValueError('Select a published project')
|
|
86
|
+
if not formats or not set(formats) <= {'pdf', 'pptx', 'xlsx'}:
|
|
87
|
+
raise ValueError('Select at least one valid format')
|
|
88
|
+
start, end = form.get('start', [''])[0], form.get('end', [''])[0]
|
|
89
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
90
|
+
generator = MonthlyReportGenerator(config, run_source=source)
|
|
91
|
+
files = generator.generate(start, end, project=project, formats=formats,
|
|
92
|
+
output_dir=Path(tmp))
|
|
93
|
+
output = io.BytesIO()
|
|
94
|
+
with zipfile.ZipFile(output, 'w', zipfile.ZIP_DEFLATED) as archive:
|
|
95
|
+
for path in files:
|
|
96
|
+
archive.write(path, arcname=path.name)
|
|
97
|
+
body = output.getvalue()
|
|
98
|
+
self.send_response(200)
|
|
99
|
+
self.send_header('Content-Type', 'application/zip')
|
|
100
|
+
self.send_header('Content-Disposition', 'attachment; filename="test-report.zip"')
|
|
101
|
+
self.send_header('Content-Length', str(len(body)))
|
|
102
|
+
self.send_header('X-Content-Type-Options', 'nosniff')
|
|
103
|
+
self.end_headers()
|
|
104
|
+
self.wfile.write(body)
|
|
105
|
+
except Exception as exc:
|
|
106
|
+
try:
|
|
107
|
+
projects = source.projects()
|
|
108
|
+
except Exception:
|
|
109
|
+
projects = []
|
|
110
|
+
status = 400 if isinstance(exc, ValueError) else 500
|
|
111
|
+
self._send(status, _page(projects, str(exc)), 'text/html; charset=utf-8')
|
|
112
|
+
|
|
113
|
+
return Handler
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def serve(config, port=8766, open_browser=True):
|
|
117
|
+
server = ThreadingHTTPServer(('127.0.0.1', port), make_handler(config))
|
|
118
|
+
url = f'http://127.0.0.1:{server.server_port}/'
|
|
119
|
+
print(f'[Monthly Report] Open {url}')
|
|
120
|
+
if open_browser:
|
|
121
|
+
webbrowser.open(url)
|
|
122
|
+
try:
|
|
123
|
+
server.serve_forever()
|
|
124
|
+
except KeyboardInterrupt:
|
|
125
|
+
pass
|
|
126
|
+
finally:
|
|
127
|
+
server.server_close()
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Read published run files without involving the local pytest database."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from datetime import date
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
from .config import ReportingConfig
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class PublishedRunSource:
|
|
11
|
+
def __init__(self, config=None, s3_client=None):
|
|
12
|
+
self.config = config or ReportingConfig()
|
|
13
|
+
self._s3_client = s3_client
|
|
14
|
+
|
|
15
|
+
def _client(self):
|
|
16
|
+
if self._s3_client is None:
|
|
17
|
+
try:
|
|
18
|
+
import boto3
|
|
19
|
+
except ImportError as exc:
|
|
20
|
+
raise RuntimeError("Install test-reporting[s3,reports] for S3 reports") from exc
|
|
21
|
+
self._s3_client = boto3.client('s3', region_name=self.config.S3_REGION)
|
|
22
|
+
return self._s3_client
|
|
23
|
+
|
|
24
|
+
def _key(self, *parts):
|
|
25
|
+
return '/'.join(p.strip('/') for p in (self.config.S3_PREFIX, *parts) if p)
|
|
26
|
+
|
|
27
|
+
def projects(self):
|
|
28
|
+
"""Return project names found in the published run tree."""
|
|
29
|
+
if self.config.STORE_TYPE == 's3':
|
|
30
|
+
prefix = self._key('runs') + '/'
|
|
31
|
+
names = []
|
|
32
|
+
pages = self._client().get_paginator('list_objects_v2').paginate(
|
|
33
|
+
Bucket=self.config.S3_BUCKET, Prefix=prefix, Delimiter='/')
|
|
34
|
+
for page in pages:
|
|
35
|
+
for entry in page.get('CommonPrefixes', []):
|
|
36
|
+
name = entry['Prefix'][len(prefix):].rstrip('/')
|
|
37
|
+
if name:
|
|
38
|
+
names.append(name)
|
|
39
|
+
return sorted(set(names))
|
|
40
|
+
root = self.config.STORE_PATH / 'runs'
|
|
41
|
+
return sorted(p.name for p in root.iterdir() if p.is_dir()) if root.exists() else []
|
|
42
|
+
|
|
43
|
+
def runs(self, project, start_date, end_date):
|
|
44
|
+
"""Read a selected project's runs in an inclusive date range."""
|
|
45
|
+
if project not in self.projects():
|
|
46
|
+
raise ValueError(f"Published project not found: {project}")
|
|
47
|
+
start = date.fromisoformat(start_date)
|
|
48
|
+
end = date.fromisoformat(end_date)
|
|
49
|
+
if start > end:
|
|
50
|
+
raise ValueError('Start date must be on or before end date')
|
|
51
|
+
if self.config.STORE_TYPE == 's3':
|
|
52
|
+
prefix = self._key('runs', project) + '/'
|
|
53
|
+
pages = self._client().get_paginator('list_objects_v2').paginate(
|
|
54
|
+
Bucket=self.config.S3_BUCKET, Prefix=prefix)
|
|
55
|
+
for page in pages:
|
|
56
|
+
for entry in page.get('Contents', []):
|
|
57
|
+
key = entry['Key']
|
|
58
|
+
if not key.endswith('.json'):
|
|
59
|
+
continue
|
|
60
|
+
body = self._client().get_object(Bucket=self.config.S3_BUCKET, Key=key)['Body'].read()
|
|
61
|
+
run = json.loads(body)
|
|
62
|
+
if self._selected(run, project, start, end):
|
|
63
|
+
yield run
|
|
64
|
+
else:
|
|
65
|
+
for path in sorted((self.config.STORE_PATH / 'runs' / project).glob('*.json')):
|
|
66
|
+
run = json.loads(path.read_text(encoding='utf-8'))
|
|
67
|
+
if self._selected(run, project, start, end):
|
|
68
|
+
yield run
|
|
69
|
+
|
|
70
|
+
@staticmethod
|
|
71
|
+
def _selected(run, project, start, end):
|
|
72
|
+
if run.get('project_name') != project:
|
|
73
|
+
return False
|
|
74
|
+
try:
|
|
75
|
+
run_date = date.fromisoformat(run['timestamp'][:10])
|
|
76
|
+
except (KeyError, TypeError, ValueError):
|
|
77
|
+
return False
|
|
78
|
+
return start <= run_date <= end
|
|
@@ -9,7 +9,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
|
|
9
9
|
|
|
10
10
|
setup(
|
|
11
11
|
name='test-reporting',
|
|
12
|
-
version='4.
|
|
12
|
+
version='4.2.0',
|
|
13
13
|
description='Multi-project test reporting dashboard — collect results locally or push to S3',
|
|
14
14
|
long_description=long_description,
|
|
15
15
|
long_description_content_type="text/markdown",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: test-reporting
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.2.0
|
|
4
4
|
Summary: Multi-project test reporting dashboard — collect results locally or push to S3
|
|
5
5
|
Home-page: https://github.com/amahdy77/test-reporting.git
|
|
6
6
|
Author: Ashfaqur Mahdy
|
|
@@ -261,6 +261,7 @@ dashboard_max_runs_per_suite = 50 # Run history per suite (default: 50)
|
|
|
261
261
|
| `test-report cleanup` | Delete old runs from local SQLite |
|
|
262
262
|
| `test-report cleanup-artifacts` | Delete old screenshots and traces (preserves data) |
|
|
263
263
|
| `test-report monthly-report` | Generate monthly test report (PPTX/XLSX/PDF) |
|
|
264
|
+
| `test-report monthly-ui` | Open local project and date picker for reports |
|
|
264
265
|
|
|
265
266
|
### Cleaning up old data
|
|
266
267
|
|
|
@@ -319,19 +320,22 @@ retention_days = 90 # Keep 90 days of artifacts and data
|
|
|
319
320
|
|
|
320
321
|
## Monthly Reports
|
|
321
322
|
|
|
322
|
-
Generate
|
|
323
|
+
Generate a report for one project from its published run history. The report reader supports the same local or S3 store used by `test-report publish`; it does not need a copied SQLite database.
|
|
323
324
|
|
|
324
325
|
### Quick Start
|
|
325
326
|
|
|
326
327
|
```bash
|
|
327
|
-
# Install with report dependencies
|
|
328
|
+
# Install with report dependencies and S3 support
|
|
328
329
|
pip install test-reporting[s3,reports]
|
|
329
330
|
|
|
330
|
-
#
|
|
331
|
-
test-report monthly-
|
|
331
|
+
# Open the local project and date picker
|
|
332
|
+
test-report monthly-ui --config reporting.ini
|
|
333
|
+
|
|
334
|
+
# Generate without the UI (defaults to the last 30 days)
|
|
335
|
+
test-report monthly-report --project "My Project" --format pptx,xlsx,pdf
|
|
332
336
|
|
|
333
337
|
# Custom date range
|
|
334
|
-
test-report monthly-report --start 2026-08-01 --end 2026-08-31 --format xlsx
|
|
338
|
+
test-report monthly-report --project "My Project" --start 2026-08-01 --end 2026-08-31 --format xlsx
|
|
335
339
|
|
|
336
340
|
# Specific project
|
|
337
341
|
test-report monthly-report --project "My Project" --format pptx
|
|
@@ -346,7 +350,7 @@ test-report monthly-report --project "My Project" --format pptx
|
|
|
346
350
|
- 📁 File health report
|
|
347
351
|
- 💡 Actionable recommendations
|
|
348
352
|
|
|
349
|
-
**See [
|
|
353
|
+
**See [REPORT_GENERATOR.md](REPORT_GENERATOR.md) for setup and metric definitions.**
|
|
350
354
|
|
|
351
355
|
---
|
|
352
356
|
|
|
@@ -6,8 +6,10 @@ reporting/classifier.py
|
|
|
6
6
|
reporting/cli.py
|
|
7
7
|
reporting/config.py
|
|
8
8
|
reporting/monthly_report.py
|
|
9
|
+
reporting/monthly_ui.py
|
|
9
10
|
reporting/plugin.py
|
|
10
11
|
reporting/publisher.py
|
|
12
|
+
reporting/run_source.py
|
|
11
13
|
reporting/storage.py
|
|
12
14
|
reporting/exporters/__init__.py
|
|
13
15
|
reporting/exporters/pdf_exporter.py
|
|
@@ -21,4 +23,5 @@ test_reporting.egg-info/SOURCES.txt
|
|
|
21
23
|
test_reporting.egg-info/dependency_links.txt
|
|
22
24
|
test_reporting.egg-info/entry_points.txt
|
|
23
25
|
test_reporting.egg-info/requires.txt
|
|
24
|
-
test_reporting.egg-info/top_level.txt
|
|
26
|
+
test_reporting.egg-info/top_level.txt
|
|
27
|
+
tests/test_published_monthly_report.py
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import io
|
|
3
|
+
import importlib.util
|
|
4
|
+
import tempfile
|
|
5
|
+
import threading
|
|
6
|
+
import unittest
|
|
7
|
+
import urllib.error
|
|
8
|
+
import urllib.parse
|
|
9
|
+
import urllib.request
|
|
10
|
+
import zipfile
|
|
11
|
+
from http.server import ThreadingHTTPServer
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from types import SimpleNamespace
|
|
14
|
+
|
|
15
|
+
from reporting.monthly_report import MonthlyReportGenerator
|
|
16
|
+
from reporting.monthly_ui import make_handler
|
|
17
|
+
from reporting.run_source import PublishedRunSource
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class PublishedMonthlyReportTests(unittest.TestCase):
|
|
21
|
+
def setUp(self):
|
|
22
|
+
self.tmp = tempfile.TemporaryDirectory()
|
|
23
|
+
self.addCleanup(self.tmp.cleanup)
|
|
24
|
+
root = Path(self.tmp.name)
|
|
25
|
+
self.config = SimpleNamespace(STORE_TYPE='local', STORE_PATH=root,
|
|
26
|
+
S3_PREFIX='', S3_BUCKET='', S3_REGION='us-east-1')
|
|
27
|
+
folder = root / 'runs' / 'Project A'
|
|
28
|
+
folder.mkdir(parents=True)
|
|
29
|
+
self._write(folder / 'previous.json', '2026-09-30T10:00:00', ['passed', 'failed'])
|
|
30
|
+
self._write(folder / 'current.json', '2026-10-01T10:00:00', ['passed', 'passed'])
|
|
31
|
+
|
|
32
|
+
def _write(self, path, timestamp, statuses):
|
|
33
|
+
tests = [{'test_name': f'test_{i}', 'file_name': 'test_workflow.py',
|
|
34
|
+
'status': status, 'duration_seconds': 2.0,
|
|
35
|
+
'failure_type': 'ASSERTION' if status == 'failed' else None}
|
|
36
|
+
for i, status in enumerate(statuses)]
|
|
37
|
+
path.write_text(json.dumps({
|
|
38
|
+
'run_id': path.stem, 'project_name': 'Project A', 'suite_name': 'suite',
|
|
39
|
+
'timestamp': timestamp, 'total_tests': len(tests),
|
|
40
|
+
'passed': statuses.count('passed'), 'failed': statuses.count('failed'),
|
|
41
|
+
'skipped': 0, 'pass_rate': statuses.count('passed') / len(tests) * 100,
|
|
42
|
+
'duration_seconds': 4.0, 'all_tests': tests,
|
|
43
|
+
'failed_tests': [{'test_name': t['test_name'], 'file_name': t['file_name'],
|
|
44
|
+
'failure_type': 'ASSERTION', 'is_soft_fail': False}
|
|
45
|
+
for t in tests if t['status'] == 'failed'],
|
|
46
|
+
'test_files': [],
|
|
47
|
+
}), encoding='utf-8')
|
|
48
|
+
|
|
49
|
+
def test_project_and_inclusive_date_selection(self):
|
|
50
|
+
source = PublishedRunSource(self.config)
|
|
51
|
+
self.assertEqual(source.projects(), ['Project A'])
|
|
52
|
+
runs = list(source.runs('Project A', '2026-10-01', '2026-10-01'))
|
|
53
|
+
self.assertEqual([r['run_id'] for r in runs], ['current'])
|
|
54
|
+
with self.assertRaises(ValueError):
|
|
55
|
+
list(source.runs('Unknown', '2026-10-01', '2026-10-01'))
|
|
56
|
+
|
|
57
|
+
def test_metrics_use_published_test_details(self):
|
|
58
|
+
generator = MonthlyReportGenerator(self.config)
|
|
59
|
+
data = generator.collect_data('2026-09-30', '2026-10-01', 'Project A')
|
|
60
|
+
metrics = generator.calculate_metrics(data)
|
|
61
|
+
self.assertEqual(metrics['summary']['total_runs'], 2)
|
|
62
|
+
self.assertEqual(metrics['summary']['pass_rate'], 75.0)
|
|
63
|
+
self.assertTrue(metrics['summary']['detail_complete'])
|
|
64
|
+
self.assertEqual(metrics['failure_types'][0]['count'], 1)
|
|
65
|
+
|
|
66
|
+
def test_incomplete_detail_does_not_create_misleading_test_metrics(self):
|
|
67
|
+
run_path = self.config.STORE_PATH / 'runs' / 'Project A' / 'current.json'
|
|
68
|
+
run = json.loads(run_path.read_text(encoding='utf-8'))
|
|
69
|
+
run.pop('all_tests')
|
|
70
|
+
run['passed_tests'] = []
|
|
71
|
+
run_path.write_text(json.dumps(run), encoding='utf-8')
|
|
72
|
+
generator = MonthlyReportGenerator(self.config)
|
|
73
|
+
metrics = generator.calculate_metrics(generator.collect_data('2026-09-30', '2026-10-01', 'Project A'))
|
|
74
|
+
self.assertFalse(metrics['summary']['detail_complete'])
|
|
75
|
+
self.assertEqual(metrics['file_health'], [])
|
|
76
|
+
self.assertEqual(metrics['slowest_tests'], [])
|
|
77
|
+
|
|
78
|
+
def test_s3_reader_uses_run_prefix_and_pagination(self):
|
|
79
|
+
run = json.loads((self.config.STORE_PATH / 'runs' / 'Project A' / 'current.json').read_text())
|
|
80
|
+
|
|
81
|
+
class Paginator:
|
|
82
|
+
def paginate(self, **kwargs):
|
|
83
|
+
if kwargs.get('Delimiter'):
|
|
84
|
+
return [{'CommonPrefixes': [{'Prefix': 'prod/runs/Project A/'}]}]
|
|
85
|
+
return [{'Contents': [{'Key': 'prod/runs/Project A/current.json'}]},
|
|
86
|
+
{'Contents': [{'Key': 'prod/runs/Project A/other.txt'}]}]
|
|
87
|
+
|
|
88
|
+
class Client:
|
|
89
|
+
def get_paginator(self, operation):
|
|
90
|
+
self_operation = operation
|
|
91
|
+
assert self_operation == 'list_objects_v2'
|
|
92
|
+
return Paginator()
|
|
93
|
+
|
|
94
|
+
def get_object(self, **kwargs):
|
|
95
|
+
return {'Body': io.BytesIO(json.dumps(run).encode())}
|
|
96
|
+
|
|
97
|
+
config = SimpleNamespace(STORE_TYPE='s3', STORE_PATH=Path(self.tmp.name),
|
|
98
|
+
S3_PREFIX='prod', S3_BUCKET='bucket', S3_REGION='us-east-1')
|
|
99
|
+
source = PublishedRunSource(config, s3_client=Client())
|
|
100
|
+
self.assertEqual(source.projects(), ['Project A'])
|
|
101
|
+
self.assertEqual(len(list(source.runs('Project A', '2026-10-01', '2026-10-01'))), 1)
|
|
102
|
+
|
|
103
|
+
def test_local_date_picker_lists_projects_and_rejects_bad_dates(self):
|
|
104
|
+
server = ThreadingHTTPServer(('127.0.0.1', 0), make_handler(self.config))
|
|
105
|
+
worker = threading.Thread(target=server.serve_forever, daemon=True)
|
|
106
|
+
worker.start()
|
|
107
|
+
self.addCleanup(server.server_close)
|
|
108
|
+
self.addCleanup(server.shutdown)
|
|
109
|
+
address = f'http://127.0.0.1:{server.server_port}'
|
|
110
|
+
with urllib.request.urlopen(address + '/') as response:
|
|
111
|
+
self.assertIn(b'Project A', response.read())
|
|
112
|
+
form = urllib.parse.urlencode({'project': 'Project A', 'start': '2026-10-02',
|
|
113
|
+
'end': '2026-10-01', 'format': 'pdf'}).encode()
|
|
114
|
+
with self.assertRaises(urllib.error.HTTPError) as raised:
|
|
115
|
+
urllib.request.urlopen(address + '/generate', data=form)
|
|
116
|
+
self.assertEqual(raised.exception.code, 400)
|
|
117
|
+
raised.exception.close()
|
|
118
|
+
if importlib.util.find_spec('openpyxl'):
|
|
119
|
+
good_form = urllib.parse.urlencode({'project': 'Project A', 'start': '2026-10-01',
|
|
120
|
+
'end': '2026-10-01', 'format': 'xlsx'}).encode()
|
|
121
|
+
with urllib.request.urlopen(address + '/generate', data=good_form) as response:
|
|
122
|
+
self.assertEqual(response.headers.get_content_type(), 'application/zip')
|
|
123
|
+
with zipfile.ZipFile(io.BytesIO(response.read())) as archive:
|
|
124
|
+
self.assertEqual(len(archive.namelist()), 1)
|
|
125
|
+
self.assertTrue(archive.namelist()[0].endswith('.xlsx'))
|
|
126
|
+
|
|
127
|
+
@unittest.skipUnless(all(importlib.util.find_spec(x) for x in ('pptx', 'openpyxl', 'reportlab')),
|
|
128
|
+
'Install test-reporting[reports] to test exports')
|
|
129
|
+
def test_generate_all_formats_with_previous_period(self):
|
|
130
|
+
generator = MonthlyReportGenerator(self.config)
|
|
131
|
+
files = generator.generate('2026-10-01', '2026-10-01', project='Project A',
|
|
132
|
+
formats=['pdf', 'pptx', 'xlsx'],
|
|
133
|
+
output_dir=self.config.STORE_PATH / 'exports')
|
|
134
|
+
self.assertEqual({p.suffix for p in files}, {'.pdf', '.pptx', '.xlsx'})
|
|
135
|
+
self.assertTrue(all(p.stat().st_size > 0 for p in files))
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
if __name__ == '__main__':
|
|
139
|
+
unittest.main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|