python- to the test report plus the time

Manually writing test reports really tired, so I want to learn python! Liberate yourself!

Use python time module reports the current time added to enhance the name recognition test report file.

First, understand the time module

1.time.time (): Get the current timestamp
2.time.ctime (): the current time string
3.time.location (): struct_time form the current time
4.time.strftime (): Get the current time may be formatted string time

Second, the common format symbols:

% Y: Year with century, 2020
% Y: Year without century, 20 is
% m: Month
% d: talent
% H: the 24 hour time
% M: min
% S: seconds

Third, code implementation

1. Get the current time in a format

now = time.strftime("%y%m%d",time.localtime(time.time())) #获取当前时间

2. The current time is added to the file name in the test report

newbook.save('./test_report_demo/kt0-M3RY-'+now+'.xls')

As shown the figure:
Here Insert Picture Description

Published 11 original articles · won praise 0 · Views 247

Guess you like

Origin blog.csdn.net/zkw_1998/article/details/103936904