import socket def test_server(self): testServ = Server.CommandServer(localhost, 5000) server_thread = threading.Thread(target=testServ.start_listening) server_thread.start() # On my computer, 0.0000001 is the minimum sleep time or the # client might connect before server thread binds and listens # Other computers will differ. I wanted a low number to make tests fast time.sleep(0.000001) # This is a fake test client that is just going to attempt a connect and disconnect fake_client = socket.socket() fake_client.settimeout(1) fake_client.connect((localhost, 5000)) fake_client.close() # server thread finishes server_thread.join()