[英]falcon, AttributeError: 'API' object has no attribute 'create'
我正在尝试测试我的猎鹰路线,但测试始终失败,并且看起来我做对了所有事情。
我的app.py
import falcon
from resources.static import StaticResource
api = falcon.API()
api.add_route('/', StaticResource())
和我的测试目录tests/static.py
from falcon import testing
import pytest
from app import api
@pytest.fixture(scope='module')
def client():
# Assume the hypothetical `myapp` package has a
# function called `create()` to initialize and
# return a `falcon.API` instance.
return testing.TestClient(api.create())
def test_get_message(client):
result = client.simulate_get('/')
assert result.status_code == 200
请帮忙,为什么我得到AttributeError: 'API' object has no attribute 'create'
错误? 谢谢。
您在app.py
中缺少假设的 create()
函数。
您的app.py
应该如下所示:
import falcon
from resources.static import StaticResource
def create():
api = falcon.API()
api.add_route('/', StaticResource())
return api
api = create()
然后在您的tests/static.py
应如下所示:
from falcon import testing
import pytest
from app import create
@pytest.fixture(scope='module')
def client():
return testing.TestClient(create())
def test_get_message(client):
result = client.simulate_get('/')
assert result.status_code == 200
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.