user3153987
user3153987

Reputation: 151

Warning (from warnings module): ResourceWarning: unclosed <socket.socket object, fd=404, family=2, type=1, proto=0> using selenium

import unittest
from selenium import webdriver
from selenium.webdriver.common.keys import Keys


class PythonOrgSearch(unittest.TestCase):

    def setUp(self):
        self.driver = webdriver.Firefox()

    def test_search_in_python_org(self):
        driver = self.driver
        driver.get("http://www.python.org")
        self.assertIn("Python", driver.title)
        elem = driver.find_element_by_name("q")
        elem.send_keys("selenium")
        elem.send_keys(Keys.RETURN)
        self.assertIn("Google", driver.title)

    def tearDown(self):
        self.driver.close()

if __name__=="__main__":
    unittest.main()

I am getting this warning. What is wrong?

Warning (from warnings module):
  File "C:\Python33\lib\site-packages\selenium-2.37.2-py3.3.egg\selenium\webdriver\firefox\firefox_binary.py", line 95
    while not utils.is_connectable(self.profile.port):
ResourceWarning: unclosed <socket.socket object, fd=400, family=2, type=1, proto=0>

Upvotes: 15

Views: 12815

Answers (2)

iainH
iainH

Reputation: 1084

I run my tests with the -W flag thus:

python -W ignore -m unittest my_tests  

or

python -W ignore -m unittest my_tests.MyIndividualTest     

that suppresses the ResourceWarning but still allows assertion error reports.


BTW I found that:

if __name__ == '__main__':
    unittest.main(warnings='ignore')  

works when invoking python my_tests.py when every test is to be run, but this invocation precludes running individual tests.

I couldn't figure out how else to use unittest.main(warnings='ignore') without encountering errors I put down to recursive inclusion of unittest libraries.

(selenium==2.44.0 under Python 3.4.2)

Upvotes: 10

hwjp
hwjp

Reputation: 16071

It's a known bug:

http://code.google.com/p/selenium/issues/detail?id=5923

It's safe to ignore it though. If you're using Python 3, you can do:

unittest.main(warnings='ignore')

See Python 3 unittest docs.

In Python 2, you'd use something like this:

with warnings.catch_warnings(record=True):
     unittest.main()

cf the Python 2 warnings docs

If you'll forgive the shameless self-promotion, there's lots more info on selenium in a wee book I've written, here.

Upvotes: 23

Related Questions