zoukankan      html  css  js  c++  java
  • 【Selenium】【BugList9】windows环境,fp = open("./"+ time.strftime("%Y-%m-%d %H:%M:%S") + " result.html",'wb'),报错:OSError: [Errno 22] Invalid argument: './2018-09-05 10:29:32 result.html'

    【代码】

    if __name__=="__main__":
        suite = unittest.TestSuite()
        suite.addTest(Baidu("test_baidu"))
        
        url ="./"+ time.strftime("%Y-%m-%d %H:%M:%S") + " result.html"
        fp = open(url,'wb')
        runner = HTMLTestRunner(stream = fp,
                                title = 'Report of Baidu_search',
                                description = 'TestCase run')
        
        runner.run(suite)
        fp.close()

    【报错】

    ==================== RESTART: C:/Users/admin/Desktop/1.py ====================
    Traceback (most recent call last):
    File "C:/Users/admin/Desktop/1.py", line 31, in <module>
    fp = open("./"+ time.strftime("%Y-%m-%d %H:%M:%S") + " result.html",'wb')
    OSError: [Errno 22] Invalid argument: './2018-09-05 10:29:32 result.html'

     

    【解决思路】

    1.python IDLE中:open("./result.html",'wb'),成功

    2.去掉“%Y-%m-%d %H:%M:%S”中空格,仍报错 

    3.修改“%Y-%m-%d %H:%M:%S”中‘:’ 为 ‘-’,成功—>冒号 ‘:’ 引起

    4.在python IDLE中,执行 time.strftime("%Y-%m-%d %H:%M:%S") 可成功,但open方法执行却不行?

    5.在Windows下,创建文件名带冒号的文件,再用open方法打开,结果:

    6.结论:Windows环境,不能创建文件名带英文冒号:的文件,所以open方法创建/打开文件失败

    【代码-修改后】

    if __name__=="__main__":
        suite = unittest.TestSuite()
        suite.addTest(Baidu("test_baidu"))
        
        url ="./"+ time.strftime("%Y-%m-%d %H_%M_%S") + " result.html"
        fp = open(url,'wb')
        runner = HTMLTestRunner(stream = fp,
                                title = 'Report of Baidu_search',
                                description = 'TestCase run')
        
        runner.run(suite)
        fp.close()

    【Ending】

    微信公众号“粒粒的测试笔记

  • 相关阅读:
    校园网络安全CTF 第一题 和 你真了解我吗?
    href="#" 链接到当前页面
    Redis的Set无序集合命令
    Redis的List链表类型命令
    Redis的String、Hash类型命令
    redis2.8.xx安装配置
    ZendFramework安装配置
    复选框的全选、反选
    列表中被点击的行加亮背景色
    SQL中的替换函数replace()使用
  • 原文地址:https://www.cnblogs.com/yllil/p/9590761.html
Copyright © 2011-2022 走看看