> ## Documentation Index
> Fetch the complete documentation index at: https://docs.featherframework.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Test database

> Every test gets a fresh database, plus the Flask-Login fixture gotcha that makes every request resolve to the same user.

Tests run against a separate test database, configured automatically. Each test gets a
fresh state:

<Steps>
  <Step title="Before each test">Tables are created.</Step>
  <Step title="After each test">Tables are dropped and the engine is disposed.</Step>
</Steps>

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:

```python theme={null}
@pytest.fixture
def seeded(app):
    with app.app_context():
        db.session.add(User(email='a@example.com'))
        db.session.commit()
    # context closed before the test makes any request
    return app
```

<Warning>
  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.
</Warning>
