python - falcon, AttributeError: 'API' object has no attribute 'create' -
i'm trying test falcon routes, tests failed, , looks make things right.
my app.py
import falcon resources.static import staticresource api = falcon.api() api.add_route('/', staticresource())
and test directory tests/static.py
from falcon import testing import pytest app import api @pytest.fixture(scope='module') def client(): # assume hypothetical `myapp` package has # function called `create()` initialize , # return `falcon.api` instance. return testing.testclient(api.create()) def test_get_message(client): result = client.simulate_get('/') assert result.status_code == 200
help please, why got attributeerror: 'api' object has no attribute 'create'
error? thanks.
you missing hypothetical create()
function in app.py
.
your app.py
should following:
import falcon resources.static import staticresource def create(): api = falcon.api() api.add_route('/', staticresource()) return api api = create()
then in tests/static.py
should like:
from falcon import testing import pytest 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
Comments
Post a Comment