Reputation: 6421
I am trying to create test cases for my migration functions (called with migrations.RunPython
). My idea was to create a test case that doesn’t run migrations before starting, neither syncdb to create the database in one step. After this, I’m planning to run the first step, run associated tests, run the second step then its associated tests, etc. Is this possible somehow, or if not, is it possible to test migration functions in any way?
Upvotes: 1
Views: 845
Reputation: 1199
When you use django's TestCase
, it has an explicit requirement that the database must be setup, which means all migrations must be applied. If you want to test things without the migrations happening, you cannot use TestCase
.
Use a testing toolkit that doesn't depend on django, like pytest
and write your own code to test. You can always import django models and settings explicitly.
Your tests would first run the explicit tests where database is not created, after which, the other tests can be run containing TestCase
.
I'm not sure whether such a setup is possible with manage.py
, but you can certainly create your own script (maybe using fabric
or plain python
) to run tests in your choice of order.
Upvotes: 1