Jay Taylor's notes
back to listing indexDoing what you aren’t supposed to do with Django tests | HeadSpin Blog
[web search]HeadSpin Blog
You know what the truth is? The truth is something my neighbor believes. If I want to make friends with him I ask him what he believes. He tells me and I say “Yeah, Yeah ain’t it the Truth?”
Doing what you aren’t supposed to do with Django tests
So I wanted to run my django test scripts against my development database. The django test system really wants to create a database from scratch but I wanted to see whether I could run against my local scratch copy since its already got a lot of data in it and I am too lazy to make fixtures etc.
Some googling produced alot of very helpful “You are doing it wrong!” comments which is fine as far as that goes but I am not good at taking advice.
Digging a little deeper I found you can override the DjangoTestSuiteRunner. Now we are getting somewhere.
put this in settings.py:
TEST_RUNNER = 'myapp.test_extras.NoTestDbDatabaseTestRunner'
And then define the NoTestDbDatabaseTestRunner:
I’m feeling pretty good about this. I try a simple “test” which just counts the number of items in a particular table.
Only what I get is a completely wiped out local db. Nice.
The trick is that my TestCase was using
from django.test import TestCase
which has its own ideas about what to do with the database and it was wiping it out. Switching to:
unittest.TestCase
or
from django.test import SimpleTestCase
if you are using django trunk. Looks like it fixes the problem, but it doesn’t make me feel any better.
Maybe I should just listen more.
Leave a Reply
Your email address will not be published. Required fields are marked *
Name *
Email *
Website
Comment
You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
Notify me of follow-up comments by email.
Notify me of new posts by email.
M | T | W | T | F | S | S |
---|---|---|---|---|---|---|
« Feb | ||||||
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 | 31 |