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

How to create test databases and connect them to the test Sanic app? #68

Open
Maksim-Burtsev opened this issue May 27, 2023 · 2 comments

Comments

@Maksim-Burtsev
Copy link

I am trying to test app with TortoiseORM and i dont understand what is the right way to setup my test application in fixture.

I was tried to make with listeners and fixtures but i am always how problems with event loop, or tortoise can't connect to the database, or fixture doesnt work and etc. And i can't find any example on stackoverflow/github with testing Sanic with tortoise and test databases.

Can you show me the best way to setup tests for testing Sanic & TortoiseORM on the test db (e.g. sqlite) ?

p.s I think i can use sqlite:///:memory for

@ahopkins
Copy link
Member

ahopkins commented May 30, 2023

I cannot advise on any best practices with an ORM, you will have to turn to them for that.

GENERALLY, I would say your testing should NOT hit any database. Instead you should use mocking to retrieve fake data in your tests. When you have to start incorporating networking calls and state management into tests it gets pretty complex quickly.

I cover some testing strategies specifically dealing with DB interactions in my book. Generally, I just point people to the companion code in GH, but I think the concepts you are aiming for are much more complex and you really should look deeper into the topic of testing. IMO the problem is in strategy not implementation.

@lb1mg
Copy link

lb1mg commented Jan 26, 2024

Need to understand the working of sanic-testing, specifically app running part, when we provide an app fixture which typically has our routes/blueprints and middlewares and maybe listeners, are listeners not executed when it "runs" the app?

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

No branches or pull requests

3 participants