Docs on unit testing with Django say:
If your tests rely on database access such as creating or querying models, be sure to create your test classes as subclasses of
django.test.TestCase
rather thanunittest.TestCase
.Using unittest.TestCase avoids the cost of running each test in a transaction and flushing the database, but if your tests interact with the database their behavior will vary based on the order that the test runner executes them. This can lead to unit tests that pass when run in isolation but fail when run in a suite.
I'm using django.test.TestCase
. If a test creates a database entry, it persists across other test classes too. I can select all the objects manually and delete them in setUp
but that looks like a hack. Any suggestions on what could I be doing wrong that's resulting in database not getting flushed after each test case.
Aucun commentaire:
Enregistrer un commentaire