convert datetime object to string in summary data structure

This commit is contained in:
debugtalk
2018-07-20 18:15:22 +08:00
parent d35743ab94
commit b48dbc27b8
3 changed files with 7 additions and 6 deletions

View File

@@ -1,7 +1,7 @@
__title__ = 'HttpRunner' __title__ = 'HttpRunner'
__description__ = 'One-stop solution for HTTP(S) testing.' __description__ = 'One-stop solution for HTTP(S) testing.'
__url__ = 'https://github.com/HttpRunner/HttpRunner' __url__ = 'https://github.com/HttpRunner/HttpRunner'
__version__ = '1.5.2' __version__ = '1.5.3'
__author__ = 'debugtalk' __author__ = 'debugtalk'
__author_email__ = 'mail@debugtalk.com' __author_email__ = 'mail@debugtalk.com'
__license__ = 'MIT' __license__ = 'MIT'

View File

@@ -49,7 +49,7 @@ def get_summary(result):
if getattr(result, "records", None): if getattr(result, "records", None):
summary["time"] = { summary["time"] = {
'start_at': datetime.fromtimestamp(result.start_at), 'start_at': result.start_at,
'duration': result.duration 'duration': result.duration
} }
summary["records"] = result.records summary["records"] = result.records
@@ -77,14 +77,15 @@ def render_html_report(summary, html_report_name=None, html_report_template=None
logger.log_debug("render data: {}".format(summary)) logger.log_debug("render data: {}".format(summary))
report_dir_path = os.path.join(os.getcwd(), "reports") report_dir_path = os.path.join(os.getcwd(), "reports")
start_datetime = summary["time"]["start_at"].strftime('%Y-%m-%d-%H-%M-%S') start_at_timestamp = int(summary["time"]["start_at"])
summary["time"]["start_datetime"] = datetime.fromtimestamp(start_at_timestamp).strftime('%Y-%m-%d %H:%M:%S')
if html_report_name: if html_report_name:
summary["html_report_name"] = html_report_name summary["html_report_name"] = html_report_name
report_dir_path = os.path.join(report_dir_path, html_report_name) report_dir_path = os.path.join(report_dir_path, html_report_name)
html_report_name += "-{}.html".format(start_datetime) html_report_name += "-{}.html".format(start_at_timestamp)
else: else:
summary["html_report_name"] = "" summary["html_report_name"] = ""
html_report_name = "{}.html".format(start_datetime) html_report_name = "{}.html".format(start_at_timestamp)
if not os.path.isdir(report_dir_path): if not os.path.isdir(report_dir_path):
os.makedirs(report_dir_path) os.makedirs(report_dir_path)

View File

@@ -150,7 +150,7 @@
<tr> <tr>
<th>START AT</th> <th>START AT</th>
<td colspan="4">{{time.start_at.strftime('%Y-%m-%d %H:%M:%S')}}</td> <td colspan="4">{{time.start_datetime}}</td>
</tr> </tr>
<tr> <tr>
<th>DURATION</th> <th>DURATION</th>