1
1
# This Source Code Form is subject to the terms of the Mozilla Public
2
2
# License, v. 2.0. If a copy of the MPL was not distributed with this
3
3
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
- import datetime
4
+ from datetime import datetime , timezone
5
5
import json
6
6
import math
7
7
import os
20
20
21
21
class BaseReport :
22
22
def __init__ (self , report_path , config , report_data , template , css ):
23
+ report_path_expanded = self ._expand_path (report_path )
23
24
self ._report_path = (
24
- Path .cwd () / Path (os . path . expandvars ( report_path ) ).expanduser ()
25
+ Path .cwd () / Path (report_path_expanded ).expanduser ()
25
26
)
26
27
self ._report_path .parent .mkdir (parents = True , exist_ok = True )
27
28
self ._config = config
@@ -32,6 +33,7 @@ def __init__(self, report_path, config, report_data, template, css):
32
33
)
33
34
34
35
self ._reports = defaultdict (dict )
36
+ self ._generated = datetime .now (tz = timezone .utc )
35
37
self ._report = report_data
36
38
self ._report .title = self ._report_path .name
37
39
self ._suite_start_time = time .time ()
@@ -40,7 +42,16 @@ def __init__(self, report_path, config, report_data, template, css):
40
42
def css (self ):
41
43
# implement in subclasses
42
44
return
43
-
45
+
46
+ def _expand_path (self , report_path ):
47
+ # generated_time: UTC date and time, in ISO format with : replaced with -.
48
+ # report-%(generated_time).html will become report-2025-10-08T21-45-08.237134.html
49
+ path_expanded = os .path .expandvars (report_path )
50
+ path_expanded := path_expanded % {
51
+ "generated_time" : self ._generated .isoformat ().replace (":" , "-" ),
52
+ }
53
+ return path_expanded
54
+
44
55
def _asset_filename (self , test_id , extra_index , test_index , file_extension ):
45
56
return "{}_{}_{}.{}" .format (
46
57
re .sub (r"[^\w.]" , "_" , test_id ),
@@ -50,13 +61,12 @@ def _asset_filename(self, test_id, extra_index, test_index, file_extension):
50
61
)[- self ._max_asset_filename_length :]
51
62
52
63
def _generate_report (self , self_contained = False ):
53
- generated = datetime .datetime .now ()
54
64
test_data = self ._report .data
55
65
test_data = json .dumps (test_data )
56
66
rendered_report = self ._template .render (
57
67
title = self ._report .title ,
58
- date = generated .strftime ("%d-%b-%Y" ),
59
- time = generated .strftime ("%H:%M:%S" ),
68
+ date = self . _generated .strftime ("%d-%b-%Y" ),
69
+ time = self . _generated .strftime ("%H:%M:%S" ),
60
70
version = __version__ ,
61
71
styles = self .css ,
62
72
run_count = self ._run_count (),
0 commit comments