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

A 'SQLAlchemy' instance has already been registered on this Flask app. Import and use that instance instead. #557

Open
Patrickcob opened this issue Aug 26, 2023 · 1 comment
Labels

Comments

@Patrickcob
Copy link

If was curious about the way you made the unit tests in flask. I have a similar project with a very close architecture. I have a much more recent version of flask, flask-sqlalchemy and etc. I was curious if anyone was having problem with this project related to unit testing.

While creating an instance of the app in the test, it raise an error that RuntimeError: A 'SQLAlchemy' instance has already been registered on this Flask app. Import and use that instance instead.

From my understanding, when using flask test --coverage, it will create an instance of the app, than run the tests that try to create their own instances of the app. but in the create_app function, it tries to init the db with db.init_app(app) and it seems that, without surprise, there is a runtime error raised, because the database used is already in used, in this case, its a in-memory db. Something wrong or is this part of the newer flask and incompatible with this project?

@miguelgrinberg
Copy link
Owner

The problem is that you are trying to attach two Flask-SQLAlchemy extensions to the same Flask app instance. This suggests you are not creating a brand new app for each test, as is done in the tests in this project.

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

No branches or pull requests

2 participants