5

我正在使用flask_sockets库构建一个应用程序。我该如何测试它?

这是我要为其编写单元测试的代码示例:

import flask
from flask import Flask
from flask_sockets import Sockets

app = Flask(__name__)
sockets = Sockets(app)

ws_conns = []


@sockets.route('/echo')
def echo_socket(ws):
    #on connect
    ws_conns.append(ws)

    #while connected
    while True:
        # message = ws.receive()
        # if message is None:
        # #socket has closed/errored
        #     break
        for c in ws_conns:
            c.send('hello and goodbye!')

    #disconnected
    ws_conns.remove(ws)
    ws.close()

我已经使用了这个 git repo中的代码。

4

0 回答 0