Flask 使用JWT烧瓶和pytest

Flask 使用JWT烧瓶和pytest,flask,pytest,flask-jwt,Flask,Pytest,Flask Jwt,我试图在使用Flask JWT模块的Flask应用程序中测试/auth端点 import json import pytest @pytest.mark.usefixtures("testapp") class TestURLs: def test_auth(self, testapp): rv = testapp.get('/auth', data=json.dumps({'username':'bob', 'password': 'pw'}

我试图在使用Flask JWT模块的Flask应用程序中测试/auth端点

import json
import pytest

@pytest.mark.usefixtures("testapp")
class TestURLs:

    def test_auth(self, testapp):
        rv = testapp.get('/auth',
            data=json.dumps({'username':'bob', 'password': 'pw'}),
            content_type='application/json')
        ... test assertion ...
当我运行flask服务器并且可以请求JWT令牌时,/auth端点可以完美地工作

但是,当测试运行时,它会从服务器接收此响应

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL manually please check your spelling and try again.</p>

404找不到
找不到
在服务器上找不到请求的URL。如果您手动输入URL,请检查拼写并重试


是否有办法配置测试夹具以识别/auth端点?

在哪里初始化JWT扩展并将其与应用程序链接?您确定应用程序在测试环境中以相同的方式初始化吗?另外,您在问题中提到了
/auth
端点,但在实际测试中提到了
/api/auth
?我编辑了uri以确保一致性。我会回来回答你剩下的问题。谢谢。在my
testapp()
方法中,我需要初始化jwt,就像在flask
app.py
中初始化jwt一样:
jwt=jwt(app,authenticate,identity)
新来者注意:使用扩展的flask jwt,最近进行了更新,并且有更好的文档。您在哪里初始化JWT扩展并将其与应用程序链接?您确定应用程序在测试环境中以相同的方式初始化吗?另外,您在问题中提到了
/auth
端点,但在实际测试中提到了
/api/auth
?我编辑了uri以确保一致性。我会回来回答你剩下的问题。谢谢。在my
testapp()
方法中,我需要初始化jwt,就像在flask
app.py
中初始化jwt一样:
jwt=jwt(app,authenticate,identity)
新来者注意:取而代之的是,找到的flask jwt Extended,它最近更新了,并且有更好的文档。