Python 如何使用Flask登录在Flask中模拟和测试多用户登录/注销?

Python 如何使用Flask登录在Flask中模拟和测试多用户登录/注销?,python,testing,flask,flask-login,Python,Testing,Flask,Flask Login,测试多个用户的身份验证过程需要多个会话/客户端。我尝试使用app.test\u client(…)进行测试,如下代码所示,它可以测试单个用户的登录/注销功能,但我无法确定当多个用户在自己的会话中登录/注销时,它是否仍然有效 setUp, tearDown, and other branche tests... def test_login(self): """Check if server can handle login successfully. """ with

测试多个用户的身份验证过程需要多个会话/客户端。我尝试使用
app.test\u client(…)
进行测试,如下代码所示,它可以测试单个用户的登录/注销功能,但我无法确定当多个用户在自己的会话中登录/注销时,它是否仍然有效

setUp, tearDown, and other branche tests...

def test_login(self):
    """Check if server can handle login successfully.
    """
    with self.client as c:
        login_res = c.post(API.login, data=self.valid_user)
        assert_equals(login_res.get_json(), {
            'data': {'userName': 'user'}, 'status': 200,
            'msg': 'login success.'
        })

def test_logout(self):
    """Check if server can handle user logout.
    """
    with self.client as c:
        # login user first
        c.post(API.login, data=self.valid_user)
        # then log out.
        res = c.get(API.logout)
        assert_equals(res.get_json(), {
            'data': {'userName': 'user'}, 'status': 200,
            'msg': 'logout success.'
        })