Flask + pytest example/ boilerplate
Hey everybody. During the last few days I have been reading about "tests" and how to do them with '''pytest'''. The problem is Im having troubles to make it work with Flask. Do any of you have a simple example or boiler plate I can use as a guide? (Im using sqlite as a database). Thanks.
3 comments · 94% upvoted · other discussions
Consider looking at flask-testing. That might not be 100% the library you want, but the documentation will give you a good place to start.
FYI, if you’re interacting with a relational database in flask, I highly suggest using an ORM (Object Relational Mapper). The most popular is SQLAlchemy, and there’s an integration with Flask called flask-sqlalchemy. This should completely abstract away which database you’re using, allowing you to not worry about whether you’re currently connected to SQLite, Postgres, or MySQL. You need to worry about choosing which of them to use of course, but the code is the same according to the ORM.