[英]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.