【问题标题】:ResourceWarning: unclosed file error while running python selenium unittestResourceWarning:运行python selenium unittest时出现未关闭的文件错误
【发布时间】:2020-06-25 14:19:09
【问题描述】:

在运行 python selenium unittest 时,我看到一个错误:

/usr/lib/python3.6/unittest/case.py:605: ResourceWarning: unclosed file <_io.TextIOWrapper name='/home/newuser/scable/HTML_Test_Runner_ReportTest.html' mode='w' encoding='UTF-8'>
  testMethod()
.
----------------------------------------------------------------------
Ran 1 test in 0.006s

OK
sys:1: ResourceWarning: unclosed <socket.socket fd=4, family=AddressFamily.AF_INET, type=SocketKind.SOCK_STREAM, proto=6, laddr=('127.0.0.1', 42230), raddr=('127.0.0.1', 34255)>

这个错误是什么意思?

【问题讨论】:

    标签: python python-3.x selenium selenium-webdriver python-unittest


    【解决方案1】:

    此错误消息...

    /usr/lib/python3.6/unittest/case.py:605: ResourceWarning: unclosed file
    

    ...暗示在尝试访问未关闭的文件时出现ResourceWarning


    此问题特定于 ,因为 ResourceWarnings 仅由 Python3 发出。最可能的原因是,您打开了一个文件,使用了它,但后来忘记关闭该文件。虽然当 Python 注意到文件对象已死时,它会自动代表您关闭打开的文件,但这会在经过相当长的一段时间后发生。

    如果您尝试在仍然打开的文件中执行某些操作,例如 ,此问题也可能会发生。试图删除一个文件。

    但是,当您尝试打开文件 HTML_Test_Runner_ReportTest.html 而文件仍在处理中时,似乎会出现此问题。

    一个简单的解决方案是等待HTML_Test_Runner_ReportTest.html 文件被完全处理然后访问它。

    【讨论】:

    • 我尝试杀死所有打开的文件并再次运行它但得到同样的错误
    • 我正在使用 python 3.6.0 版本 ps -ef | 开发 Ubuntu 18.04 grep .py 4505 3693 0 13:23 pts/0 00:00:00 grep --color=auto .py (我也杀死了这个过程)但仍然得到同样的错误,即使我尝试杀死所有的 .html 文件但 stll同样的错误 ps -ef | grep .html newuser 4482 3693 0 13:22 pts/0 00:00:00 grep --color=auto .html 即使我等了 2 天仍然在第 3 天得到同样的错误
    猜你喜欢
    • 2020-08-06
    • 1970-01-01
    • 1970-01-01
    • 2013-06-19
    • 1970-01-01
    • 2013-03-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多