Permalink
Browse files

Flush transaction_test_case tests after test run instead of before

  • Loading branch information...
pelme committed May 4, 2012
1 parent 2918f12 commit c9caa881fc0975a4eab6cfa20f465e3898613ec4
Showing with 20 additions and 2 deletions.
  1. +20 −2 pytest_django/utils.py
View
@@ -1,3 +1,5 @@
+from django.db import connections
+from django.core.management import call_command
from django.test.testcases import SimpleTestCase, TransactionTestCase, TestCase
@@ -23,8 +25,24 @@ def get_django_unittest(item):
def django_setup_item(item):
- get_django_unittest(item)._pre_setup()
+ if 'transaction_test_case' in item.keywords:
+ # Nothing needs to be done
+ pass
+ else:
+ # Use the standard TestCase teardown
+ get_django_unittest(item)._pre_setup()
def django_teardown_item(item):
- get_django_unittest(item)._post_teardown()
+
+ if 'transaction_test_case' in item.keywords:
+ # Flush the database and close database connections
+ # Django does this by default *before* each test instead of after
+ for db in connections:
+ call_command('flush', verbosity=0, interactive=False, database=db)
+
+ for conn in connections.all():
+ conn.close()
+ else:
+ # Use the standard TestCase teardown
+ get_django_unittest(item)._post_teardown()

0 comments on commit c9caa88

Please sign in to comment.