[英]ResourceWarning: unclosed file error while running python selenium unittest
While running python selenium unittest I'm seeing an error:在运行 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)>
What does this error means?这个错误是什么意思?
This error message...这个错误信息...
/usr/lib/python3.6/unittest/case.py:605: ResourceWarning: unclosed file
...implies that there was a ResourceWarning while trying to access an unclosed file . ...暗示在尝试访问未关闭的文件时出现ResourceWarning 。
This issue is specific to python-3.x as the ResourceWarnings are only emitted with Python3 .此问题特定于python-3.x,因为ResourceWarnings仅随Python3发出。 The most probhable reason is, you have opened a file, used it, but then forgot to close the file.最可能的原因是,您打开了一个文件,使用了它,但后来忘记关闭该文件。 Though Python automatically closes the opened file on behalf of you when it notices that the file object is dead but this occurs after some significant time has elapsed.尽管Python在注意到文件对象已死时会自动代表您关闭打开的文件,但这发生在经过一段时间后。
This issue can also occur specifically on windows if you try to perform some operations in a file which is still open eg trying to delete a file.如果您尝试在仍然打开的文件中执行某些操作(例如尝试删除文件),则此问题也可能发生在Windows 上。
However, this issue seems to arising as you try to open the file HTML_Test_Runner_ReportTest.html
when the file was still under process.但是,当您在文件仍在处理过程中尝试打开文件HTML_Test_Runner_ReportTest.html
时,似乎会出现此问题。
A simple solution would be to wait for the HTML_Test_Runner_ReportTest.html
file to be completely processed and then access it.一个简单的解决方案是等待HTML_Test_Runner_ReportTest.html
文件被完全处理,然后访问它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.