@@ -235,3 +235,46 @@ class TestCaseWithTrDbFixture(TestCase):
235
235
def test_simple (self ):
236
236
# We only want to check setup/teardown does not conflict
237
237
assert 1
238
+
239
+
240
+ def test_pdb_enabled (django_testdir ):
241
+ """
242
+ Make sure the database is flushed and tests are isolated when
243
+ using the --pdb option.
244
+
245
+ See issue #405 for details:
246
+ https://github.com/pytest-dev/pytest-django/issues/405
247
+ """
248
+
249
+ django_testdir .create_test_module ('''
250
+ import os
251
+
252
+ from django.test import TestCase
253
+ from django.conf import settings
254
+
255
+ from .app.models import Item
256
+
257
+ class TestPDBIsolation(TestCase):
258
+ def setUp(self):
259
+ """setUp should be called after starting a transaction"""
260
+ assert Item.objects.count() == 0
261
+ Item.objects.create(name='Some item')
262
+ Item.objects.create(name='Some item again')
263
+
264
+ def test_count(self):
265
+ self.assertEqual(Item.objects.count(), 2)
266
+ assert Item.objects.count() == 2
267
+ Item.objects.create(name='Foo')
268
+ self.assertEqual(Item.objects.count(), 3)
269
+
270
+ def test_count_again(self):
271
+ self.test_count()
272
+
273
+ def tearDown(self):
274
+ """tearDown should be called before rolling back the database"""
275
+ assert Item.objects.count() == 3
276
+
277
+ ''' )
278
+
279
+ result = django_testdir .runpytest_subprocess ('-v' , '--pdb' )
280
+ assert result .ret == 0
0 commit comments