test-reporting 4.1.1__tar.gz → 4.2.1__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.
Files changed (29) hide show
  1. {test_reporting-4.1.1 → test_reporting-4.2.1}/PKG-INFO +11 -7
  2. {test_reporting-4.1.1 → test_reporting-4.2.1}/README.md +10 -6
  3. {test_reporting-4.1.1 → test_reporting-4.2.1}/reporting/cli.py +20 -3
  4. {test_reporting-4.1.1 → test_reporting-4.2.1}/reporting/exporters/pdf_exporter.py +5 -0
  5. {test_reporting-4.1.1 → test_reporting-4.2.1}/reporting/exporters/pptx_exporter.py +5 -0
  6. {test_reporting-4.1.1 → test_reporting-4.2.1}/reporting/exporters/xlsx_exporter.py +5 -0
  7. {test_reporting-4.1.1 → test_reporting-4.2.1}/reporting/monthly_report.py +103 -13
  8. test_reporting-4.2.1/reporting/monthly_ui.py +127 -0
  9. test_reporting-4.2.1/reporting/run_source.py +101 -0
  10. {test_reporting-4.1.1 → test_reporting-4.2.1}/setup.py +1 -1
  11. {test_reporting-4.1.1 → test_reporting-4.2.1}/test_reporting.egg-info/PKG-INFO +11 -7
  12. {test_reporting-4.1.1 → test_reporting-4.2.1}/test_reporting.egg-info/SOURCES.txt +4 -1
  13. test_reporting-4.2.1/tests/test_published_monthly_report.py +146 -0
  14. {test_reporting-4.1.1 → test_reporting-4.2.1}/LICENSE +0 -0
  15. {test_reporting-4.1.1 → test_reporting-4.2.1}/reporting/__init__.py +0 -0
  16. {test_reporting-4.1.1 → test_reporting-4.2.1}/reporting/classifier.py +0 -0
  17. {test_reporting-4.1.1 → test_reporting-4.2.1}/reporting/config.py +0 -0
  18. {test_reporting-4.1.1 → test_reporting-4.2.1}/reporting/exporters/__init__.py +0 -0
  19. {test_reporting-4.1.1 → test_reporting-4.2.1}/reporting/plugin.py +0 -0
  20. {test_reporting-4.1.1 → test_reporting-4.2.1}/reporting/publisher.py +0 -0
  21. {test_reporting-4.1.1 → test_reporting-4.2.1}/reporting/storage.py +0 -0
  22. {test_reporting-4.1.1 → test_reporting-4.2.1}/reporting/templates/index.html +0 -0
  23. {test_reporting-4.1.1 → test_reporting-4.2.1}/reporting/templates/project.html +0 -0
  24. {test_reporting-4.1.1 → test_reporting-4.2.1}/reporting/templates/run.html +0 -0
  25. {test_reporting-4.1.1 → test_reporting-4.2.1}/setup.cfg +0 -0
  26. {test_reporting-4.1.1 → test_reporting-4.2.1}/test_reporting.egg-info/dependency_links.txt +0 -0
  27. {test_reporting-4.1.1 → test_reporting-4.2.1}/test_reporting.egg-info/entry_points.txt +0 -0
  28. {test_reporting-4.1.1 → test_reporting-4.2.1}/test_reporting.egg-info/requires.txt +0 -0
  29. {test_reporting-4.1.1 → test_reporting-4.2.1}/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.1.1
3
+ Version: 4.2.1
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 comprehensive monthly test reports with metrics, charts, and actionable insights.
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
- # Generate monthly report (CLI only)
331
- test-report monthly-report --format pptx,xlsx,pdf
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 [MONTHLY_REPORTS.md](MONTHLY_REPORTS.md) for full documentation.**
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 comprehensive monthly test reports with metrics, charts, and actionable insights.
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
- # Generate monthly report (CLI only)
290
- test-report monthly-report --format pptx,xlsx,pdf
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 [MONTHLY_REPORTS.md](MONTHLY_REPORTS.md) for full documentation.**
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='Filter by project name')
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=30)
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.storage = TestResultStorage(config=self.config)
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)
@@ -55,9 +68,28 @@ class MonthlyReportGenerator:
55
68
  if project:
56
69
  print(f"[Monthly Report] Project filter: {project}")
57
70
 
58
- # Collect and calculate metrics
59
- data = self.collect_data(start_date, end_date, project)
71
+ # Read the current and comparison periods in one store pass.
72
+ period_days = (end - start).days + 1
73
+ previous_end = start - timedelta(days=1)
74
+ previous_start = previous_end - timedelta(days=period_days - 1)
75
+ combined = self.collect_data(previous_start.isoformat(), end_date, project)
76
+ current_ids = {r['id'] for r in combined['runs'] if r.get('timestamp', '')[:10] >= start_date}
77
+ previous_ids = {r['id'] for r in combined['runs'] if r.get('timestamp', '')[:10] < start_date}
78
+ data = {
79
+ 'runs': [r for r in combined['runs'] if r['id'] in current_ids],
80
+ 'results': [r for r in combined['results'] if r['run_id'] in current_ids],
81
+ }
82
+ previous_runs = [r for r in combined['runs'] if r['id'] in previous_ids]
83
+ if not data['runs']:
84
+ raise ValueError(f'No runs found for {project} from {start_date} to {end_date}')
60
85
  metrics = self.calculate_metrics(data, top_n)
86
+ previous_total = sum(r.get('total_tests', 0) for r in previous_runs)
87
+ previous_passed = sum(r.get('passed', 0) for r in previous_runs)
88
+ summary = metrics['summary']
89
+ summary['previous_runs'] = len(previous_runs)
90
+ summary['previous_pass_rate'] = round(previous_passed / previous_total * 100, 1) if previous_total else None
91
+ summary['pass_rate_change'] = (round(summary['pass_rate'] - summary['previous_pass_rate'], 1)
92
+ if summary['previous_pass_rate'] is not None else None)
61
93
 
62
94
  # Generate report metadata
63
95
  report_meta = {
@@ -103,11 +135,46 @@ class MonthlyReportGenerator:
103
135
 
104
136
  def _make_filename(self, start_date: str, end_date: str, project: Optional[str], ext: str) -> str:
105
137
  """Generate filename for report."""
106
- project_part = f"{project.replace(' ', '-')}_" if project else ""
138
+ import re
139
+ project_part = re.sub(r'[^A-Za-z0-9._-]+', '-', project).strip('.-') + '_' if project else ''
107
140
  return f"monthly-report_{project_part}{start_date}_to_{end_date}.{ext}"
108
141
 
109
142
  def collect_data(self, start_date: str, end_date: str, project: Optional[str] = None) -> Dict[str, Any]:
110
- """Collect test run data from SQLite database."""
143
+ """Collect test results from published run files or legacy SQLite."""
144
+ if self.source == 'published':
145
+ runs = []
146
+ results = []
147
+ for index, run in enumerate(self.run_source.runs(project, start_date, end_date), 1):
148
+ runs.append({**run, 'id': index})
149
+ failed_details = {
150
+ (t.get('test_name'), t.get('file_name')): t
151
+ for t in run.get('failed_tests', [])
152
+ }
153
+ tests = run.get('all_tests')
154
+ if tests is None:
155
+ tests = run.get('passed_tests', []) + run.get('failed_tests', [])
156
+ for test in tests:
157
+ status = test.get('status')
158
+ if not status:
159
+ status = 'failed' if (test.get('test_name'), test.get('file_name')) in failed_details else 'passed'
160
+ detail = failed_details.get((test.get('test_name'), test.get('file_name')), {})
161
+ results.append({
162
+ 'run_id': index,
163
+ 'test_name': test.get('test_name'),
164
+ 'file_name': test.get('file_name'),
165
+ 'status': status,
166
+ 'duration_seconds': test.get('duration_seconds') or 0,
167
+ 'failure_type': test.get('failure_type') or detail.get('failure_type'),
168
+ 'is_soft_fail': detail.get('is_soft_fail', False),
169
+ 'created_at': run.get('timestamp', ''),
170
+ })
171
+ runs.sort(key=lambda r: r.get('timestamp', ''))
172
+ return {'runs': runs, 'results': results, 'start_date': start_date,
173
+ 'end_date': end_date, 'project': project}
174
+ return self._collect_sqlite_data(start_date, end_date, project)
175
+
176
+ def _collect_sqlite_data(self, start_date, end_date, project):
177
+ """Read the legacy local database when explicitly requested."""
111
178
  import sqlite3
112
179
 
113
180
  conn = sqlite3.connect(self.storage.db_path)
@@ -200,6 +267,16 @@ class MonthlyReportGenerator:
200
267
  recommendations = self._generate_recommendations(
201
268
  summary, failure_hotspots, flaky_tests, slowest_tests
202
269
  )
270
+
271
+ # Older published files may only contain selected test details. Never
272
+ # present test-level rates or trends as complete when records are missing.
273
+ if not summary['detail_complete']:
274
+ flaky_tests = []
275
+ slowest_tests = []
276
+ performance_regressions = []
277
+ file_health = []
278
+ recommendations = self._generate_recommendations(summary, failure_hotspots, [], [])
279
+ recommendations.insert(0, 'Detailed test history is incomplete for this period; test-level analysis is omitted.')
203
280
 
204
281
  return {
205
282
  'summary': summary,
@@ -239,6 +316,7 @@ class MonthlyReportGenerator:
239
316
  total_tests = sum(r.get('total_tests', 0) for r in runs)
240
317
  total_passed = sum(r.get('passed', 0) for r in runs)
241
318
  total_failed = sum(r.get('failed', 0) for r in runs)
319
+ total_skipped = sum(r.get('skipped', 0) for r in runs)
242
320
 
243
321
  pass_rate = round((total_passed / total_tests * 100) if total_tests > 0 else 0, 1)
244
322
 
@@ -248,18 +326,23 @@ class MonthlyReportGenerator:
248
326
  if r.get('status') == 'passed' or r.get('is_soft_fail')
249
327
  )
250
328
  functional_total = len([r for r in results if r.get('status') in ['passed', 'failed']])
329
+ detail_complete = functional_total >= total_passed + total_failed
251
330
  functional_pass_rate = round(
252
- (functional_passed / functional_total * 100) if functional_total > 0 else 0, 1
331
+ (functional_passed / functional_total * 100) if detail_complete and functional_total > 0 else pass_rate, 1
253
332
  )
254
333
 
255
334
  # Health score based on functional pass rate
256
335
  health_score = round(functional_pass_rate)
257
336
 
258
- # Calculate trend (compare first half vs second half)
337
+ # Calculate trend from weighted test executions in each half.
259
338
  mid_point = len(runs) // 2
260
339
  if mid_point > 0:
261
- first_half_rate = sum(r.get('pass_rate', 0) for r in runs[:mid_point]) / mid_point
262
- second_half_rate = sum(r.get('pass_rate', 0) for r in runs[mid_point:]) / (len(runs) - mid_point)
340
+ first_total = sum(r.get('total_tests', 0) for r in runs[:mid_point])
341
+ second_total = sum(r.get('total_tests', 0) for r in runs[mid_point:])
342
+ first_half_rate = (sum(r.get('passed', 0) for r in runs[:mid_point]) / first_total * 100
343
+ if first_total else 0)
344
+ second_half_rate = (sum(r.get('passed', 0) for r in runs[mid_point:]) / second_total * 100
345
+ if second_total else 0)
263
346
  trend_diff = second_half_rate - first_half_rate
264
347
  trend = f"{'+' if trend_diff >= 0 else ''}{trend_diff:.1f}%"
265
348
  else:
@@ -271,6 +354,9 @@ class MonthlyReportGenerator:
271
354
  'total_tests': total_tests,
272
355
  'total_passed': total_passed,
273
356
  'total_failed': total_failed,
357
+ 'total_skipped': total_skipped,
358
+ 'detail_count': len(results),
359
+ 'detail_complete': detail_complete,
274
360
  'pass_rate': pass_rate,
275
361
  'functional_pass_rate': functional_pass_rate,
276
362
  'trend': trend,
@@ -429,8 +515,12 @@ class MonthlyReportGenerator:
429
515
  return []
430
516
 
431
517
  # Split into recent (last 7 days) and historical (7-30 days ago)
432
- cutoff_recent = (datetime.now() - timedelta(days=7)).isoformat()
433
- cutoff_historical = (datetime.now() - timedelta(days=30)).isoformat()
518
+ period_end = max((r.get('timestamp', '')[:10] for r in runs), default='')
519
+ if not period_end:
520
+ return []
521
+ report_end = date.fromisoformat(period_end)
522
+ cutoff_recent = (report_end - timedelta(days=7)).isoformat()
523
+ cutoff_historical = (report_end - timedelta(days=30)).isoformat()
434
524
 
435
525
  recent_durations = defaultdict(list)
436
526
  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 ZIP downloads when generation finishes. Watch the PowerShell window for progress; large date ranges may take a while.</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,101 @@
1
+ """Read published run files without involving the local pytest database."""
2
+
3
+ import json
4
+ from concurrent.futures import ThreadPoolExecutor
5
+ from datetime import date
6
+ from pathlib import Path
7
+
8
+ from .config import ReportingConfig
9
+
10
+
11
+ class PublishedRunSource:
12
+ def __init__(self, config=None, s3_client=None):
13
+ self.config = config or ReportingConfig()
14
+ self._s3_client = s3_client
15
+
16
+ def _client(self):
17
+ if self._s3_client is None:
18
+ try:
19
+ import boto3
20
+ except ImportError as exc:
21
+ raise RuntimeError("Install test-reporting[s3,reports] for S3 reports") from exc
22
+ self._s3_client = boto3.client('s3', region_name=self.config.S3_REGION)
23
+ return self._s3_client
24
+
25
+ def _key(self, *parts):
26
+ return '/'.join(p.strip('/') for p in (self.config.S3_PREFIX, *parts) if p)
27
+
28
+ def projects(self):
29
+ """Return project names found in the published run tree."""
30
+ if self.config.STORE_TYPE == 's3':
31
+ prefix = self._key('runs') + '/'
32
+ names = []
33
+ pages = self._client().get_paginator('list_objects_v2').paginate(
34
+ Bucket=self.config.S3_BUCKET, Prefix=prefix, Delimiter='/')
35
+ for page in pages:
36
+ for entry in page.get('CommonPrefixes', []):
37
+ name = entry['Prefix'][len(prefix):].rstrip('/')
38
+ if name:
39
+ names.append(name)
40
+ return sorted(set(names))
41
+ root = self.config.STORE_PATH / 'runs'
42
+ return sorted(p.name for p in root.iterdir() if p.is_dir()) if root.exists() else []
43
+
44
+ def runs(self, project, start_date, end_date):
45
+ """Read a selected project's runs in an inclusive date range."""
46
+ if project not in self.projects():
47
+ raise ValueError(f"Published project not found: {project}")
48
+ start = date.fromisoformat(start_date)
49
+ end = date.fromisoformat(end_date)
50
+ if start > end:
51
+ raise ValueError('Start date must be on or before end date')
52
+ if self.config.STORE_TYPE == 's3':
53
+ prefix = self._key('runs', project) + '/'
54
+ pages = self._client().get_paginator('list_objects_v2').paginate(
55
+ Bucket=self.config.S3_BUCKET, Prefix=prefix)
56
+ keys = []
57
+ for page in pages:
58
+ for entry in page.get('Contents', []):
59
+ key = entry['Key']
60
+ if not key.endswith('.json'):
61
+ continue
62
+ key_date = self._date_from_key(key)
63
+ if key_date is None or start <= key_date <= end:
64
+ keys.append(key)
65
+ print(f'[Monthly Report] Reading {len(keys)} published run file(s) for {project}')
66
+ def read_run(key):
67
+ body = self._client().get_object(Bucket=self.config.S3_BUCKET, Key=key)['Body'].read()
68
+ return json.loads(body)
69
+ with ThreadPoolExecutor(max_workers=8) as pool:
70
+ for run in pool.map(read_run, keys):
71
+ if self._selected(run, project, start, end):
72
+ yield run
73
+ else:
74
+ for path in sorted((self.config.STORE_PATH / 'runs' / project).glob('*.json')):
75
+ key_date = self._date_from_key(path.name)
76
+ if key_date is not None and not start <= key_date <= end:
77
+ continue
78
+ run = json.loads(path.read_text(encoding='utf-8'))
79
+ if self._selected(run, project, start, end):
80
+ yield run
81
+
82
+ @staticmethod
83
+ def _date_from_key(key):
84
+ """Use publisher run IDs to skip out-of-range objects before download."""
85
+ stem = key.rsplit('/', 1)[-1].removesuffix('.json')
86
+ if '__' not in stem:
87
+ return None
88
+ try:
89
+ return date.fromisoformat(stem.rsplit('__', 1)[-1][:10])
90
+ except ValueError:
91
+ return None
92
+
93
+ @staticmethod
94
+ def _selected(run, project, start, end):
95
+ if run.get('project_name') != project:
96
+ return False
97
+ try:
98
+ run_date = date.fromisoformat(run['timestamp'][:10])
99
+ except (KeyError, TypeError, ValueError):
100
+ return False
101
+ 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.1.1',
12
+ version='4.2.1',
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.1.1
3
+ Version: 4.2.1
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 comprehensive monthly test reports with metrics, charts, and actionable insights.
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
- # Generate monthly report (CLI only)
331
- test-report monthly-report --format pptx,xlsx,pdf
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 [MONTHLY_REPORTS.md](MONTHLY_REPORTS.md) for full documentation.**
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,146 @@
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': [
86
+ {'Key': 'prod/runs/Project A/Project-A__suite__2025-01-01T100000.json'},
87
+ {'Key': 'prod/runs/Project A/Project-A__suite__2026-10-01T100000.json'},
88
+ ]}, {'Contents': [{'Key': 'prod/runs/Project A/other.txt'}]}]
89
+
90
+ class Client:
91
+ def __init__(self):
92
+ self.downloaded = []
93
+
94
+ def get_paginator(self, operation):
95
+ assert operation == 'list_objects_v2'
96
+ return Paginator()
97
+
98
+ def get_object(self, **kwargs):
99
+ self.downloaded.append(kwargs['Key'])
100
+ return {'Body': io.BytesIO(json.dumps(run).encode())}
101
+
102
+ config = SimpleNamespace(STORE_TYPE='s3', STORE_PATH=Path(self.tmp.name),
103
+ S3_PREFIX='prod', S3_BUCKET='bucket', S3_REGION='us-east-1')
104
+ client = Client()
105
+ source = PublishedRunSource(config, s3_client=client)
106
+ self.assertEqual(source.projects(), ['Project A'])
107
+ self.assertEqual(len(list(source.runs('Project A', '2026-10-01', '2026-10-01'))), 1)
108
+ self.assertEqual(client.downloaded, ['prod/runs/Project A/Project-A__suite__2026-10-01T100000.json'])
109
+
110
+ def test_local_date_picker_lists_projects_and_rejects_bad_dates(self):
111
+ server = ThreadingHTTPServer(('127.0.0.1', 0), make_handler(self.config))
112
+ worker = threading.Thread(target=server.serve_forever, daemon=True)
113
+ worker.start()
114
+ self.addCleanup(server.server_close)
115
+ self.addCleanup(server.shutdown)
116
+ address = f'http://127.0.0.1:{server.server_port}'
117
+ with urllib.request.urlopen(address + '/') as response:
118
+ self.assertIn(b'Project A', response.read())
119
+ form = urllib.parse.urlencode({'project': 'Project A', 'start': '2026-10-02',
120
+ 'end': '2026-10-01', 'format': 'pdf'}).encode()
121
+ with self.assertRaises(urllib.error.HTTPError) as raised:
122
+ urllib.request.urlopen(address + '/generate', data=form)
123
+ self.assertEqual(raised.exception.code, 400)
124
+ raised.exception.close()
125
+ if importlib.util.find_spec('openpyxl'):
126
+ good_form = urllib.parse.urlencode({'project': 'Project A', 'start': '2026-10-01',
127
+ 'end': '2026-10-01', 'format': 'xlsx'}).encode()
128
+ with urllib.request.urlopen(address + '/generate', data=good_form) as response:
129
+ self.assertEqual(response.headers.get_content_type(), 'application/zip')
130
+ with zipfile.ZipFile(io.BytesIO(response.read())) as archive:
131
+ self.assertEqual(len(archive.namelist()), 1)
132
+ self.assertTrue(archive.namelist()[0].endswith('.xlsx'))
133
+
134
+ @unittest.skipUnless(all(importlib.util.find_spec(x) for x in ('pptx', 'openpyxl', 'reportlab')),
135
+ 'Install test-reporting[reports] to test exports')
136
+ def test_generate_all_formats_with_previous_period(self):
137
+ generator = MonthlyReportGenerator(self.config)
138
+ files = generator.generate('2026-10-01', '2026-10-01', project='Project A',
139
+ formats=['pdf', 'pptx', 'xlsx'],
140
+ output_dir=self.config.STORE_PATH / 'exports')
141
+ self.assertEqual({p.suffix for p in files}, {'.pdf', '.pptx', '.xlsx'})
142
+ self.assertTrue(all(p.stat().st_size > 0 for p in files))
143
+
144
+
145
+ if __name__ == '__main__':
146
+ unittest.main()
File without changes
File without changes