我有一个Flask
应用程序:
我的app.py:
def create_app():
app = Flask(__name__)
return app
app = create_app()
session = session_factory()
def connect_db():
engine = get_engine()
return engine.connect()
@app.route("/")
def hello():
return "Hello everyone"
我想编写一些pytest测试,因此创建了两个文件:
conftest.py:
^{pr2}$测试_端点.py
import pytest
from flask import *
def test_hello(client):
response = client.get("/")
assert response.data == b'Hello everyone'
运行pytest时,会出现以下错误:
> assert response.data == b'Hello everyone'
E assert '<!DOCTYPE HT... again.</p>\n' == 'Hello everyone'
E + Hello everyone
E - <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
E - <title>404 Not Found</title>
E - <h1>Not Found</h1>
E - <p>The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.</p>
为什么pytest
找不到终结点?我能在这里加些什么让它工作?在
在fixture中,没有向从
create_app()
获取的app
添加任何路由。在如果你考虑你的代码
,该
hello
路由只添加到该全局app
实例中,而不是从fixture获取的实例。在烧瓶教程,covers testing,uses blueprints to mount paths in the ^{} function 。你可能也想这么做;像这样。在
^{pr2}$相关问题 更多 >
编程相关推荐