Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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>
like image 694
user3153987 Avatar asked Jan 02 '14 14:01

user3153987


1 Answers

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.

like image 186
hwjp Avatar answered Oct 01 '22 19:10

hwjp