Pytest: setup testclient and DB

You must be using flask-sqlalchemy, behind the scenes, it uses the declarative extension to define your models.

By subclassing a sqlalchemy declarative base class, sqlalchemy will generate Table and mapper for you, newly created table info stores in the corresponding Metadata obj. db.create_all() actually is metadata.create_all(), which will only create tables stored in the metadata.

Therefore, before you try to create a table with metadata.create_all, you have to store the info of that table into the metadata registry first, which equals to define a declarative base subclass. In python, this means to get your class definition code executed, which in turns, import the module the classes defined.