pytest-dev / pytest-dev/pytest-django
Detect invalid migration state when using --reuse-db
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
When using --reuse-db it would be nice if pytest-django could detect that the database it's reusing has applied migrations that don't exist (due to changing branch or code edits) and rebuild it from scratch.
Our migrations take about 30 seconds to run. So per the doco here https://pytest-django.readthedocs.io/en/latest/database.html#example-work-flow-with-reuse-db-and-create-db I have --reuse-db in pytest.ini.
Which is great most of the time but frequently when I switch between branches with migrations or otherwise mess with migrations I will get a complete test suite fail (but slowly and with massive amounts of error output). Then I need to run with --create-db and further that needs to be done separately for both single and multi threaded test runs and I have to remember to take it back off the args for followup runs or I will eat another 30 seconds each time.
It would be very very nice if pytest-django realised that the set of migrations in the db and the migrations on the drive are different and did a rebuild. Even just comparing the file names would be a vast improvement.
The migration table also has an applied timestamp, so detecting that the mod time on the file is newer than the applied time might also be possible.
This was spun out from #422
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the database workflow documentation linked in the issue and the existing handling of --reuse-db and --create-db. Determine how applied migrations can be compared with migrations on disk, then verify that an invalid reused database is rebuilt automatically instead of causing the test suite to fail.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python
- Domain
- database, testing
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100