I hate hitting database in my unit tests.
Even if it’s tiny, nearly empty and easy to fill. Things only become worse when you have to test lots different cases that contradict each other and yet are small enough to justify a separate database fixture.
Thus, tonight I’m fighting my laziness to decipher django.db.models enough to be able to create slim and easy db mocks inside a nose unit test.
So far is far too late for my brain to spin at full speed and no code was produced. Yet I’ve come down to two distinct ways to implement this:
- Completely mock django.db.models.query._QuerySet to use in-test dataset and respond to various queries
- Construct in-memory python SQLite and replace application connection with the one of the unit test.
Definitely the second way is faster to either implement or fail. So will it be.
Watch for updates with working code..
Leave a Reply
You must be logged in to post a comment.