@pytest.mark.parametrize(u'localhost', (u'localhost', u'127.0.0.1'))
def test_localconnect_succeeds(localhost):
 httpd = StoppableHTTPServer((u'localhost', 0), SimpleHTTPServer.SimpleHTTPRequestHandler)
 port = httpd.socket.getsockname()[1]
 server = Thread(target=httpd.serve_forever)
 server.setDaemon(True)
 server.start()
 time.sleep(0.1)
 urlopen(u'http://{localhost:s}:{port:d}'.format(localhost=localhost, port=port)).close()

@ pytest . mark . parametrize ( u'localhost' , ( u'localhost' , u'127.0.0.1' ) ) def test_localconnect_succeeds ( localhost ) : httpd = StoppableHTTPServer ( ( u'localhost' , 0 ) , SimpleHTTPServer . SimpleHTTPRequestHandler ) port = httpd . socket . getsockname ( ) [ 1 ] server = Thread ( target = httpd . serve_forever ) server . setDaemon ( True ) server . start ( ) time . sleep ( 0.1 ) urlopen ( u'http://{localhost:s}:{port:d}' . format ( localhost = localhost , port = port ) ) . close ( )
ensure that connections to localhost are allowed .