移动测试基础 使用 Nose 框架的 html 报告插件如何让名字拥有时间戳

speng · 2018年01月02日 · 最后由 speng 回复于 2018年01月05日 · 1152 次阅读

我在做 appium 的测试时候,使用环境如下:
windows10-64bits
python-2.7
nose-1.3.7
nose-html-reporting-0.2.3,链接如下:
https://pypi.python.org/pypi/nose-html-reporting

我目前不知道该如何把系统时间附带到测试报告名字里面去,因为每跑一次自动化,新的报告内容就会覆盖旧的报告内容。
看了下使用提示就是:
--html-file=FILE Path to html file to store the report in. Default is nosetests.html in the working directory
可以设定报告的路径,但是如何把系统时间弄进去感觉没思路。
希望的报告形式是:
20180102_2140_uitestreport.html
20180102_2145_uitestreport.html
......

我把 nose 的参数放进了配置文件--nose_config.cfg
[nosetests]

with-html=True
html-report=report/mytestreport.html
etc...

report 是放报告的文件夹名字,mytestreport.html 是我自己写死的报告名字。

求大佬支招或者提供思路,万分感谢!!!

共收到 2 条回复 时间 点赞
speng 接口自动化测试,完整入门篇 中提及了此贴 01月02日 22:11

让脚本替你执行命令。

也可以用 python 来做。

基本 demo 如下:

#coding: utf-8

import os, time

def currentTime(format='%Y-%m-%d %H:%M:%S'):
    return time.strftime(format, time.localtime(time.time()))

if name == "__main__":
    now = currentTime()
    cmd = 'nosetest -s -v -c config.cfg --html-file=report_{currentTime}.html'.format(currentTime=now)
    os.system(cmd)
大东 回复

谢谢大东老师,自己慢慢琢磨!!!

需要 登录 后方可回复, 如果你还没有账号请点击这里 注册