Django: Ticket #19977: Test database not auto-flushinghttps://code.djangoproject.com/ticket/19977
<p>
I have a bunch of unit test files, all of which consist of django.test.TestCase classes.
</p>
<p>
Wrote myself a little shell script to uncomment/comment test file imports in my <code>__init__.py</code> file, so I can run tests from certain test files, based off the command line arguments I give it. I am also able to run all the tests of all the test files in one go (for regression testing purposes).
</p>
<p>
I have this one test file that has some JSON fixtures and the first test checks that a certain model/table has 3 records in it (defined by the JSON fixture).
</p>
<p>
So here is the problem: when I run this test file on its own its tests pass with flying colours, but when I run the test with all other tests, that particular test case I mentioned, fails.
</p>
<p>
When I run all the tests, the database says there are 6 records in the table/model, but there should only be 3 (from the fixture), like when the test file is run by itself.
</p>
<p>
I also tried running that test file with a few other test files (not all) and it passes. So the only time it doesn't, is when all the test files are run.
</p>
<p>
To me this seems like a bug in Django or PostgreSQL (DB I am using), because aren't Django TestCases supposed to auto-flush/reset the database between each test method, let alone test class?
</p>
<p>
Posted on the "Django users" group first (<a class="ext-link" href="https://groups.google.com/forum/#!topic/django-users/kCeAEVn8nyw"><span class="icon">​</span>https://groups.google.com/forum/#!topic/django-users/kCeAEVn8nyw</a>), but haven't got a response yet.
</p>
<p>
I'm sorry I am not able to divulge information on how to replicate the problem, but it really is as simple as: run all the test files (fails), run single test file (passes).
</p>
<p>
I was originally using Django 1.4.3, then upgraded to 1.5 (hoping it would fix the problem), but it is still there.
</p>
en-usDjangohttps://www.djangoproject.com/s/img/site/hdr_logo.gifhttps://code.djangoproject.com/ticket/19977
Trac 1.2.3anonymousTue, 05 Mar 2013 11:14:57 GMThttps://code.djangoproject.com/ticket/19977#comment:1
https://code.djangoproject.com/ticket/19977#comment:1
<p>
I managed to finally get all the tests passing together, but I did it by removing a fixture from the fixtures list.
</p>
<p>
This is very strange because the test was passing when run with just its file, but not with all other test files.
</p>
<p>
I think the problem is now related to Django signals, because I use them to automatically create some records (in the model/table in question) when a record in another model is created.
</p>
TicketJacobThu, 07 Mar 2013 16:57:56 GMTstatus changed; resolution sethttps://code.djangoproject.com/ticket/19977#comment:2
https://code.djangoproject.com/ticket/19977#comment:2
<ul>
<li><strong>status</strong>
changed from <em>new</em> to <em>closed</em>
</li>
<li><strong>resolution</strong>
set to <em>needsinfo</em>
</li>
</ul>
<p>
Without more details of how you're running tests unfortunately we probably can't fix this. I understand that you can't share private info, but with just your description to go on it sounds like you're doing something rather out of the ordinary. So I'm going to close this; if you can provide a minimal test case that reproduces the problem please feel free to reopen it.
</p>
Ticket