Example of implementation of FastAPI with tests.
This is expanding on the code examples in the article "Modern Test-Driven Development in Python" by jangia and migrating it to FastAPI from Flask.
https://testdriven.io/blog/modern-tdd/
TODO: Using the run rather than uvicorn
Set PYTHONPATH to top level directory and blog subdirectory:
$ export PYTHONPATH=pwd
:pwd
/blog
Run from top-level directory:
$ uvicorn app:app --reload
How to initialise the database from top-level:
$ python blog/init_db.py
The blog article covers in some depth how to create a blog api and testing framework around it. So this is a fully functional and tested backend.
What it doesn't cover, though, are the basics of what is being implemented and what you can expect as you progress through the tutorial.
The backend is built on top of SQLite
You can use SQLite browser to view creation of tables and data [SQLite Browser] (https://sqlitebrowser.org/)
In order to run full tests - run up the backend:
$ python blog/run.py
then ensure that the database is initialised:
$ python blog/init_db.py
And finally run the tests:
$ python -m pytest tests
$ python -m pytest tests -m 'not e2e'