public
Created

Don't attempt to connect to the Selenium server at import; Wait until the first test is run.

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
class SeleniumTestCase(LiveServerTestCase):
 
_selenium_server_running = None
 
@property
def selenium_server_running(self):
"""
Determine if we can connect to the Selenium RC server.
Only evaluated once for performance reasons.
"""
if SeleniumTestCase._selenium_server_running is not None:
return SeleniumTestCase._selenium_server_running
 
try:
conn = httplib.HTTPConnection(settings.SELENIUM_SERVER_HOST,
settings.SELENIUM_SERVER_PORT)
try:
conn.request("GET", "/selenium-server/driver/", '', {})
finally:
conn.close()
SeleniumTestCase._selenium_server_running = True
except socket.error:
SeleniumTestCase._selenium_server_running = False
 
return SeleniumTestCase._selenium_server_running
 
def setUp(self):
if not self.selenium_server_running:
message = ("Can't connect to the Selenium server using address"
" %s and port %s" % (settings.SELENIUM_SERVER_HOST,
settings.SELENIUM_SERVER_PORT))
raise SkipTest(message)
....

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.