Skip to main content
Tests run against a separate test database, configured automatically. Each test gets a fresh state:
1

Before each test

Tables are created.
2

After each test

Tables are dropped and the engine is disposed.
This means tests are isolated — one test cannot affect another.

A fixture gotcha worth knowing

Flask-Login caches the current user on g for the lifetime of an application context. A fixture that holds one app.app_context() open across requests from several test clients will resolve every request to the first user loaded. Seed your data inside a context, then make requests outside it:
This one is easy to misdiagnose. The symptom is an authorization test that passes for the first user and inexplicably fails for the second, with no obvious difference between them.