Sanic: 20.12.0 causes the parallel unittest fails with 'app ... already in use'

Created on 29 Dec 2020  路  9Comments  路  Source: sanic-org/sanic

After updating to the latest sanic 20.12.0, my pytest tests are failing with following error:
sanic.exceptions.SanicException: Sanic app name 'xxxxxx' already in use.

I reverted back to 20.9.0, and the issue was fixed. What has changed in the recent version that has caused this issue to happen?

LTS feature request help wanted intermediate release-needed urgent

Most helpful comment

v20.12.1 will have this feature.

All 9 comments

The simplest way to fix this would be to give each of the apps in your test a unique name.

import uuid

Sanic(uuid.uuid4())

Newest build adds a feature where the instance is stored in an internal class registry for later retrieval:

Sanic.get_app("my_app")

We should probably add a patch that will disable this feature. It should be available both as a config:

SANIC_REGISTER=false

and on the instance itself

Sanic(..., register=False)

Also, there should be a way to remove an app from the registry (for example as a part of a unittest teardown).

Thanks a lot @ahopkins for your prompt response.

v20.12.1 will have this feature.

Let let us know if this issue fixed! Thanks, team!

Yes.

In your conftest.py:

Sanic.test_mode = True

Or, set an env variable in your test suite: SANIC_REGISTER=False

I will be releasing sanic-test incoming days that will handle this automatically.

Thanks @ahopkins worked for my issue

@ahopkins When do you expect sanic-test to be released? I have a project using Sanic 20.12 that I need to write some tests for, and ideally I'd like to use sanic-test to do that.

I was planning on doing that tonight, but didn't quite get to it. I am shooting for an initial release tomorrow, and getting #1850 ready to merge to master.

released. Changes to come, but it's out there.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

litelife picture litelife  路  3Comments

Souldat picture Souldat  路  3Comments

vlad0337187 picture vlad0337187  路  3Comments

woutor picture woutor  路  3Comments

1067511899 picture 1067511899  路  3Comments