Getting Started With Testing in Flask
Вставка
- Опубліковано 12 вер 2024
- In this video I introduce integration testing a Flask app. You'll learn how to use the test client and how to mock API requests inside a test among other things.
Get the code I wrote in this video: prettyprinted....
Need one-on-one help with your project? I can help through my coaching program. Learn more here: prettyprinted....
Twitter: / pretty_printed
Github: github.com/pre...
Thanks Anthony - glad you are still creating Flask / Python videos.
I don't plan on stopping anytime soon. Thanks for watching.
One strange thing: it seems the login form does not have an CSRF token. I think it's oversimplified here due to lack of the token. How do you test login and register if the login form in login.html has this token?
Thank you! You are an AMAZING teacher!!!
Thanks for vid! Have a question... Lets say flask app is dockerized. Uses rq worker, redis, postgres as compose services. How should one thing about testing such application?
The main tests of your routes shouldn't change. But you could also have end-to-end tests that test everything. I'd make my project generic enough to deploy to a testing server (from something like Github actions), and then I'd use Playwright to test my app from the outside like a user.
Thanks Anthony, very helpful and informative :)
Thank you, simple and clear.
You're welcome. Thanks for watching!
This is super helpful! How do you clean the database everytime you finished testing though? I found the memory sqlite always keeping data
Do you have a video where you made the app? I can't get it to run.
so far I have got that tests are made to test a functionality. Do tests need to always pass or always fail??
Thank you man, you are the python man
Awesome as always 😀
Thanks for watching!
You're a legend!
Very helpful... Thanks a lot
Pretty cool video! Please keep it up!
Thanks for watching!
Really wish you'd mentioned it was Mac only up front
Quality content! Thanks a lot
You're welcome. Thanks for watching!
So zen… Beautiful
So this is doing tests against an in memory database vs mocking… is there a guideline for this?
Thank you! I'm not sure what do you use to login, but I really wanted to know how to test the login/logout behavior
He uses the Flask Login extension
Can we have a comman database for all the test.
For example if i want to test comment functionality
Wherein user 1 adds a post and user 2 comments in it
Not sure if that would be possible in this type where database is created for every test.
Yes you can. In Pytest there are the ideas of scopes, which construct when the fixture is destroyed. So for the app fixture, it gets destroyed after every function by default. But you can change this to things like module, class, or session. Then the database will persist between tests.
Thanks a lot :)
You're welcome. Thanks for watching!
nice
Thanks for watching!