jeancochrane / jeancochrane/pytest-flask-sqlalchemy
auto_increment during testing
- Dominant language
- Python
- Stars
- 253
- Forks
- 45
- PR merge metrics
- No merged PRs in 30d
Description
In my testing, I currently insert a row to a table that has an `auto-incrementing`, `primary_key`, `Integer` column called `id`. Even with the `db_session` fixture, every time I run the test, the `id` column increments across tests runs. The first time I run the test, `id == 1`, but the next time I run the test, `id == 2`. Everything else in the test gets rolled back, but the `id` count persists. Is there a way to ensure that the count resets across test runs?
To get around this, at the beginning of each test that involves auto-incrementing an id, I manually run a SQL command to reset the count. The SQL below is for my Postgresql backend.
```
sql = text("ALTER SEQUENCE table_id_seq RESTART WITH 1")
_db.engine.execute(sql)
```
I feel like this breaks isolation across unit tests, so I'm hoping there is a better `pytest-flask-sqlalchemy` solution.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.