Hi @pgjones , I am now seeing a new error on tests that I hadn't seen before.
In my conftest
I have the following fixture:
@pytest.fixture(scope="module")
async def create_test_app(create_db):
app = create_app(**create_db)
await app.startup()
yield app
await app.shutdown()
It seems app.shutdown()
is throwing this error:
/root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/six.py:703:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/six.py:703: in reraise
raise value
/root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/six.py:703: in reraise
raise value
/root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/pytest_asyncio/plugin.py:93: in finalizer
loop.run_until_complete(async_finalizer())
/usr/local/lib/python3.8/asyncio/base_events.py:616: in run_until_complete
return future.result()
/root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/pytest_asyncio/plugin.py:85: in async_finalizer
await gen_obj.__anext__()
conftest.py:67: in create_test_app
await app.shutdown()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <quart.app.Quart object at 0x7f9947998dc0>
async def shutdown(self) -> None:
for func in self.after_serving_funcs:
await func()
app_ctx = _app_ctx_stack.top
> await app_ctx.pop(None)
/root/.local/share/virtualenvs/quartfeed_app-1k77iZGH/lib/python3.8/site-packages/quart/app.py:2155: AttributeError
================================================================ short test summary info =================================================================
ERROR relationship/test_relationship.py::test_succesful_follow - AttributeError: 'NoneType' object has no attribute 'pop'
ERROR user/test_user.py::test_profile_edit - AttributeError: 'NoneType' object has no attribute 'pop'
Any ideas what is going on?
I'm using:
pytest = "==6.2.1"
pytest-asyncio = "==0.14.0"
application.py
I have these: @app.before_serving
async def create_db_conn():
database = await db_connection()
await database.connect()
app.dbc = database
@app.after_serving
async def close_db_conn():
await app.dbc.disconnect()
shutdown_trigger
that I think is the issue for you. This is set by default to be a signal (Ctrl-C), but as noted this is only works if Quart is run on the main thread. Instead you can specify your own shutdown_trigger
and use the run_task
method. The shutdown_trigger
should be an awaitable that is done when you want the app to shutdown.
Hi.
I've just updated quart, quart-trio and hypercorn and I'm having this mypy error:
: error: Argument 1 to "serve" has incompatible type "QuartTrio"; expected "Union[Type[ASGI2Protocol], Callable[[Union[HTTPScope, WebsocketScope, LifespanScope], Callable[[], Awaitable[Union[HTTPRequestEvent, HTTPDisconnectEvent, WebsocketConnectEvent, WebsocketReceiveEvent, WebsocketDisconnectEvent, LifespanStartupEvent, LifespanShutdownEvent]]], Callable[[Union[HTTPResponseStartEvent, HTTPResponseBodyEvent, HTTPServerPushEvent, HTTPDisconnectEvent, WebsocketAcceptEvent, WebsocketSendEvent, WebsocketResponseStartEvent, WebsocketResponseBodyEvent, WebsocketCloseEvent, LifespanStartupCompleteEvent, LifespanStartupFailedEvent, LifespanShutdownCompleteEvent, LifespanShutdownFailedEvent]], Awaitable[None]]], Awaitable[None]]]"
moves\web\__init__.py:85: error: Argument 1 to "serve" has incompatible type "QuartTrio"; expected "Union[Type[ASGI2Protocol], Callable[[Union[HTTPScope, WebsocketScope, LifespanScope], Callable[[], Awaitable[Union[HTTPRequestEvent, HTTPDisconnectEvent, WebsocketConnectEvent, WebsocketReceiveEvent, WebsocketDisconnectEvent, LifespanStartupEvent, LifespanShutdownEvent]]], Callable[[Union[HTTPResponseStartEvent, HTTPResponseBodyEvent, HTTPServerPushEvent, HTTPDisconnectEvent, WebsocketAcceptEvent, WebsocketSendEvent, WebsocketResponseStartEvent, WebsocketResponseBodyEvent, WebsocketCloseEvent, LifespanStartupCompleteEvent, LifespanStartupFailedEvent, LifespanShutdownCompleteEvent, LifespanShutdownFailedEvent]], Awaitable[None]]], Awaitable[None]]]"
the "incriminated" line is await hypercorn.trio.serve(app, config)
, where I have
app = cast(quart_trio.QuartTrio,
quart_cors.cors(quart_trio.QuartTrio(__name__),
allow_origin='*',
allow_methods=['POST'],
allow_headers=['content-type']))
It is the usage of the
shutdown_trigger
that I think is the issue for you. This is set by default to be a signal (Ctrl-C), but as noted this is only works if Quart is run on the main thread. Instead you can specify your ownshutdown_trigger
and use therun_task
method. Theshutdown_trigger
should be an awaitable that is done when you want the app to shutdown.
Thanks!
It is the usage of the
shutdown_trigger
that I think is the issue for you. This is set by default to be a signal (Ctrl-C), but as noted this is only works if Quart is run on the main thread. Instead you can specify your ownshutdown_trigger
and use therun_task
method. Theshutdown_trigger
should be an awaitable that is done when you want the app to shutdown.Thanks!
hello! apologies for poorly phrased questions in advance, i am very new to python frameworks and asyncio!
i am still having a hard time to get this to work -- trying to run a quart app to be used on a website along with bot that runs 24/7 on discord. my understanding is that this run_task() method would be run for the quart app?
scope['query_string']
and the headers etc again myself
GitLab
? Thanks your help in advance.