test-reporting 4.0.2__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.0.2 → test_reporting-4.2.0}/PKG-INFO +16 -14
- {test_reporting-4.0.2 → test_reporting-4.2.0}/README.md +15 -11
- {test_reporting-4.0.2 → test_reporting-4.2.0}/reporting/cli.py +16 -15
- {test_reporting-4.0.2 → test_reporting-4.2.0}/reporting/exporters/pdf_exporter.py +5 -0
- {test_reporting-4.0.2 → test_reporting-4.2.0}/reporting/exporters/pptx_exporter.py +5 -0
- {test_reporting-4.0.2 → test_reporting-4.2.0}/reporting/exporters/xlsx_exporter.py +5 -0
- {test_reporting-4.0.2 → 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.0.2 → test_reporting-4.2.0}/setup.py +1 -3
- {test_reporting-4.0.2 → test_reporting-4.2.0}/test_reporting.egg-info/PKG-INFO +16 -14
- {test_reporting-4.0.2 → test_reporting-4.2.0}/test_reporting.egg-info/SOURCES.txt +4 -4
- {test_reporting-4.0.2 → test_reporting-4.2.0}/test_reporting.egg-info/requires.txt +0 -2
- test_reporting-4.2.0/tests/test_published_monthly_report.py +139 -0
- test_reporting-4.0.2/reporting/report_server.py +0 -135
- test_reporting-4.0.2/reporting/templates/monthly-reports.html +0 -661
- test_reporting-4.0.2/reporting/templates/report-generator.html +0 -661
- {test_reporting-4.0.2 → test_reporting-4.2.0}/LICENSE +0 -0
- {test_reporting-4.0.2 → test_reporting-4.2.0}/reporting/__init__.py +0 -0
- {test_reporting-4.0.2 → test_reporting-4.2.0}/reporting/classifier.py +0 -0
- {test_reporting-4.0.2 → test_reporting-4.2.0}/reporting/config.py +0 -0
- {test_reporting-4.0.2 → test_reporting-4.2.0}/reporting/exporters/__init__.py +0 -0
- {test_reporting-4.0.2 → test_reporting-4.2.0}/reporting/plugin.py +0 -0
- {test_reporting-4.0.2 → test_reporting-4.2.0}/reporting/publisher.py +0 -0
- {test_reporting-4.0.2 → test_reporting-4.2.0}/reporting/storage.py +0 -0
- {test_reporting-4.0.2 → test_reporting-4.2.0}/reporting/templates/index.html +0 -0
- {test_reporting-4.0.2 → test_reporting-4.2.0}/reporting/templates/project.html +0 -0
- {test_reporting-4.0.2 → test_reporting-4.2.0}/reporting/templates/run.html +0 -0
- {test_reporting-4.0.2 → test_reporting-4.2.0}/setup.cfg +0 -0
- {test_reporting-4.0.2 → test_reporting-4.2.0}/test_reporting.egg-info/dependency_links.txt +0 -0
- {test_reporting-4.0.2 → test_reporting-4.2.0}/test_reporting.egg-info/entry_points.txt +0 -0
- {test_reporting-4.0.2 → 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.0
|
|
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
|
|
@@ -27,8 +27,6 @@ Requires-Dist: python-pptx>=0.6.21; extra == "reports"
|
|
|
27
27
|
Requires-Dist: openpyxl>=3.1.0; extra == "reports"
|
|
28
28
|
Requires-Dist: reportlab>=4.0.0; extra == "reports"
|
|
29
29
|
Requires-Dist: Pillow>=10.0.0; extra == "reports"
|
|
30
|
-
Requires-Dist: flask>=3.0.0; extra == "reports"
|
|
31
|
-
Requires-Dist: flask-cors>=4.0.0; extra == "reports"
|
|
32
30
|
Dynamic: author
|
|
33
31
|
Dynamic: author-email
|
|
34
32
|
Dynamic: classifier
|
|
@@ -263,7 +261,7 @@ dashboard_max_runs_per_suite = 50 # Run history per suite (default: 50)
|
|
|
263
261
|
| `test-report cleanup` | Delete old runs from local SQLite |
|
|
264
262
|
| `test-report cleanup-artifacts` | Delete old screenshots and traces (preserves data) |
|
|
265
263
|
| `test-report monthly-report` | Generate monthly test report (PPTX/XLSX/PDF) |
|
|
266
|
-
| `test-report
|
|
264
|
+
| `test-report monthly-ui` | Open local project and date picker for reports |
|
|
267
265
|
|
|
268
266
|
### Cleaning up old data
|
|
269
267
|
|
|
@@ -317,26 +315,30 @@ retention_days = 90 # Keep 90 days of artifacts and data
|
|
|
317
315
|
|
|
318
316
|
**`run.html?r=<id>&p=<name>`** — Run detail. Test file breakdown, every failing test with its error message, screenshot and trace links.
|
|
319
317
|
|
|
320
|
-
**`monthly-reports.html`** — Monthly report generator. Generate comprehensive reports in PowerPoint, Excel, or PDF format. (Obscure URL, not linked from main pages)
|
|
321
318
|
|
|
322
319
|
---
|
|
323
320
|
|
|
324
321
|
## Monthly Reports
|
|
325
322
|
|
|
326
|
-
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.
|
|
327
324
|
|
|
328
325
|
### Quick Start
|
|
329
326
|
|
|
330
327
|
```bash
|
|
331
|
-
# Install with report dependencies
|
|
332
|
-
pip install test-reporting[reports]
|
|
328
|
+
# Install with report dependencies and S3 support
|
|
329
|
+
pip install test-reporting[s3,reports]
|
|
333
330
|
|
|
334
|
-
#
|
|
335
|
-
test-report monthly-
|
|
331
|
+
# Open the local project and date picker
|
|
332
|
+
test-report monthly-ui --config reporting.ini
|
|
336
333
|
|
|
337
|
-
#
|
|
338
|
-
test-report
|
|
339
|
-
|
|
334
|
+
# Generate without the UI (defaults to the last 30 days)
|
|
335
|
+
test-report monthly-report --project "My Project" --format pptx,xlsx,pdf
|
|
336
|
+
|
|
337
|
+
# Custom date range
|
|
338
|
+
test-report monthly-report --project "My Project" --start 2026-08-01 --end 2026-08-31 --format xlsx
|
|
339
|
+
|
|
340
|
+
# Specific project
|
|
341
|
+
test-report monthly-report --project "My Project" --format pptx
|
|
340
342
|
```
|
|
341
343
|
|
|
342
344
|
### Features
|
|
@@ -348,7 +350,7 @@ test-report serve
|
|
|
348
350
|
- 📁 File health report
|
|
349
351
|
- 💡 Actionable recommendations
|
|
350
352
|
|
|
351
|
-
**See [
|
|
353
|
+
**See [REPORT_GENERATOR.md](REPORT_GENERATOR.md) for setup and metric definitions.**
|
|
352
354
|
|
|
353
355
|
---
|
|
354
356
|
|
|
@@ -220,7 +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
|
|
223
|
+
| `test-report monthly-ui` | Open local project and date picker for reports |
|
|
224
224
|
|
|
225
225
|
### Cleaning up old data
|
|
226
226
|
|
|
@@ -274,26 +274,30 @@ retention_days = 90 # Keep 90 days of artifacts and data
|
|
|
274
274
|
|
|
275
275
|
**`run.html?r=<id>&p=<name>`** — Run detail. Test file breakdown, every failing test with its error message, screenshot and trace links.
|
|
276
276
|
|
|
277
|
-
**`monthly-reports.html`** — Monthly report generator. Generate comprehensive reports in PowerPoint, Excel, or PDF format. (Obscure URL, not linked from main pages)
|
|
278
277
|
|
|
279
278
|
---
|
|
280
279
|
|
|
281
280
|
## Monthly Reports
|
|
282
281
|
|
|
283
|
-
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.
|
|
284
283
|
|
|
285
284
|
### Quick Start
|
|
286
285
|
|
|
287
286
|
```bash
|
|
288
|
-
# Install with report dependencies
|
|
289
|
-
pip install test-reporting[reports]
|
|
287
|
+
# Install with report dependencies and S3 support
|
|
288
|
+
pip install test-reporting[s3,reports]
|
|
290
289
|
|
|
291
|
-
#
|
|
292
|
-
test-report monthly-
|
|
290
|
+
# Open the local project and date picker
|
|
291
|
+
test-report monthly-ui --config reporting.ini
|
|
293
292
|
|
|
294
|
-
#
|
|
295
|
-
test-report
|
|
296
|
-
|
|
293
|
+
# Generate without the UI (defaults to the last 30 days)
|
|
294
|
+
test-report monthly-report --project "My Project" --format pptx,xlsx,pdf
|
|
295
|
+
|
|
296
|
+
# Custom date range
|
|
297
|
+
test-report monthly-report --project "My Project" --start 2026-08-01 --end 2026-08-31 --format xlsx
|
|
298
|
+
|
|
299
|
+
# Specific project
|
|
300
|
+
test-report monthly-report --project "My Project" --format pptx
|
|
297
301
|
```
|
|
298
302
|
|
|
299
303
|
### Features
|
|
@@ -305,7 +309,7 @@ test-report serve
|
|
|
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,19 +417,18 @@ def monthly_report():
|
|
|
415
417
|
print(f" ✓ {f}")
|
|
416
418
|
|
|
417
419
|
|
|
418
|
-
def
|
|
419
|
-
"""
|
|
420
|
+
def monthly_ui():
|
|
421
|
+
"""Open the local report generator with project and date selectors."""
|
|
420
422
|
import argparse
|
|
421
|
-
from .
|
|
422
|
-
|
|
423
|
-
parser = argparse.ArgumentParser(description='
|
|
424
|
-
parser.add_argument('--
|
|
425
|
-
parser.add_argument('--port', type=int, default=
|
|
426
|
-
parser.add_argument('--
|
|
427
|
-
|
|
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')
|
|
428
429
|
args = parser.parse_args(sys.argv[2:])
|
|
429
|
-
|
|
430
|
-
|
|
430
|
+
serve(ReportingConfig(config_file=args.config), port=args.port,
|
|
431
|
+
open_browser=not args.no_browser)
|
|
431
432
|
|
|
432
433
|
|
|
433
434
|
def main():
|
|
@@ -442,7 +443,7 @@ def main():
|
|
|
442
443
|
'cleanup': (cleanup_old_data, 'Clean up old data from local SQLite'),
|
|
443
444
|
'cleanup-artifacts': (cleanup_artifacts, 'Clean up old screenshots and traces'),
|
|
444
445
|
'monthly-report': (monthly_report, 'Generate monthly test report (PPTX/XLSX/PDF)'),
|
|
445
|
-
'
|
|
446
|
+
'monthly-ui': (monthly_ui, 'Open local project and date picker for reports'),
|
|
446
447
|
}
|
|
447
448
|
|
|
448
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
|