简体   繁体   中英

ResourceWarning: unclosed file error while running python selenium unittest

While running python selenium unittest I'm seeing an error:

/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 .


This issue is specific to as the ResourceWarnings are only emitted with 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.

This issue can also occur specifically on if you try to perform some operations in a file which is still open eg trying to delete a file.

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.

A simple solution would be to wait for the HTML_Test_Runner_ReportTest.html file to be completely processed and then access it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM