gpt4 book ai didi

python - 猎鹰,属性错误 : 'API' object has no attribute 'create'

转载 作者:太空宇宙 更新时间:2023-11-03 14:06:22 26 4
gpt4 key购买 nike

我正在尝试测试我的猎鹰路线,但测试总是失败,看起来我做对了一切。

我的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

关于python - 猎鹰,属性错误 : 'API' object has no attribute 'create' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43274942/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com