How to unittest Flask websocket server (Flask-SocketIO) How to unittest Flask websocket server (Flask-SocketIO) flask flask

How to unittest Flask websocket server (Flask-SocketIO)


Some people prefer separate apps for HTTP and WebSocket, but that is not something I would recommend blindly. There are cases in which it makes sense to do so, others that do not, specially if you are using Flask-SocketIO, which gives you a fairly powerful integration.

The Flask-SocketIO extension includes a test client, similar in concept to Flask's test client, but meant to be used with socket routes. Have you looked at that?

If you want an example application that uses Flask, Celery, Socket.IO and has a nice set of unit tests for everything, have a look at Flack: https://github.com/miguelgrinberg/flack. I gave a tutorial session at PyCon 2016 in which I cover this application in detail: https://www.youtube.com/watch?v=tdIIJuPh3SI.