You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm experiencing an issue while testing a Sanic application asynchronously using pytest. According to the Sanic documentation, the SanicASGITestClient should not spin up a server on every request. However, in my tests, it appears that the @before_server_start event is being run multiple times, which contradicts the expected behavior.
Here is a minimal example to demonstrate the issue:
When running the test, the @before_server_start event seems to be executed more than once (I tried to do example print in that section and it invokes multiple times), resulting in app.ctx.x not retaining the value set in the /save route when subsequently accessed in the /get route.
Should the @before_server_start event behave like this when using SanicASGITestClient? If this behavior is expected, how should I properly test my app to ensure state is maintained between requests during asynchronous testing?
The text was updated successfully, but these errors were encountered:
I'm experiencing an issue while testing a Sanic application asynchronously using pytest. According to the Sanic documentation, the SanicASGITestClient should not spin up a server on every request. However, in my tests, it appears that the @before_server_start event is being run multiple times, which contradicts the expected behavior.
Here is a minimal example to demonstrate the issue:
My env:
sanic==24.6.0, sanic-routing==23.12.0, sanic-testing==24.6.0
pytest==8.2.2, pytest-asyncio==0.23.7
3.12
Rocky Linux 9.4
When running the test, the
@before_server_start
event seems to be executed more than once (I tried to do example print in that section and it invokes multiple times), resulting inapp.ctx.x
not retaining the value set in the/save
route when subsequently accessed in the/get
route.Should the
@before_server_start
event behave like this when usingSanicASGITestClient
? If this behavior is expected, how should I properly test my app to ensure state is maintained between requests during asynchronous testing?The text was updated successfully, but these errors were encountered: