Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

20.12.0 causes the parallel unittest fails with 'app ... already in use' #1989

Closed
atezerjani opened this issue Dec 29, 2020 · 9 comments
Closed

Comments

@atezerjani
Copy link

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?

@ahopkins
Copy link
Member

ahopkins commented Dec 30, 2020

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).

@atezerjani
Copy link
Author

Thanks a lot @ahopkins for your prompt response.

ahopkins added a commit that referenced this issue Jan 5, 2021
* Bump to v20.12

* Update Changelog

* Add disable app registry

* squash
@ahopkins
Copy link
Member

ahopkins commented Jan 5, 2021

v20.12.1 will have this feature.

@CheneyZeng
Copy link

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

@ahopkins
Copy link
Member

ahopkins commented Jan 7, 2021

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.

@riderx
Copy link

riderx commented Jan 18, 2021

Thanks @ahopkins worked for my issue

@ashleysommer
Copy link
Member

@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.

@ahopkins
Copy link
Member

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.

@ahopkins
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants