1import logging 2from threading import Thread 3 4import pytest 5from websocket import create_connection # websocket-client 6 7import _bootstrap_ 8from websocket_server import WebsocketServer 9 10 11@pytest.fixture(scope='function') 12def server(): 13 """ Returns the response of a server after""" 14 s = WebsocketServer(0, loglevel=logging.DEBUG) 15 server_thread = Thread(target=s.run_forever) 16 server_thread.daemon = True 17 server_thread.start() 18 yield s 19 s.server_close() 20 21 22@pytest.fixture 23def session(server): 24 ws = create_connection("ws://{}:{}".format(*server.server_address)) 25 yield ws, server 26 ws.close() 27