#31308: Fixture loading fails when more than one Test case uses same fixtures
-------------------------------------+-------------------------------------
               Reporter:  Lokesh     |          Owner:  nobody
  Gurram                             |
                   Type:  Bug        |         Status:  new
              Component:  Testing    |        Version:  2.2
  framework                          |
               Severity:  Normal     |       Keywords:  Testcases, fixtures
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 If I have more than one TestCase using the same fixture, loading data
 between test cases raises unique constraint violation error on Postgres
 (works fine on SQLite)

 {{{
 class Test1(TestCase):
     fixtures = ['fixture.json']

     def test_demo(self):
         u = User.objects.get(username='testuser1')
         #some testing

 class Test2(TestCase):
     fixtures = ['fixture.json']

     def test_demo2(self):
         #some testing
         pass
 }}}

 **where my fixture.json is**
 Profile table has a one-to-one relation with User table.
 {{{
 [
 {
     "model": "app1.user",
     "pk": 1,
     "fields": {
         "password": "",
         "last_login": null,
         "is_superuser": false,
         "username": "testuser1",
         "first_name": "",
         "last_name": "",
         "is_staff": false,
         "is_active": true,
         "date_joined": "2020-02-21T12:59:17.302Z",
         "email": null,
         "groups": [],
         "user_permissions": []
     }
 },
 {
     "model": "app1.profile",
     "pk": 1,
     "fields": {
         "user": 1,
         "firebaseID": null,
         "phone": null,
         "completed_till": 0,
     }
 }
 ]

 }}}

 Running each Test Case separately works fine. But when we run them in one
 go, first Test case goes through and before the second test case executes,
 I get this error -

 {{{
 django.db.utils.IntegrityError: Problem installing fixture
 'C:\...\app1\fixtures\fixture.json': Could not load app1.Profile(pk=1):
 duplicate key value violates unique constraint "app1_profile_user_id_key"
 }}}


 Any idea why the DB is not completely cleared before trying to load the
 fixtures for the next TestCase. I tested this with Django 2.2 on Postgres
 10/12.  The problem persists in both.
 Interestingly though testing on SQLite doesn't give any problem.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31308>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/055.206678b0dbf77429e6635752a53ace66%40djangoproject.com.

Reply via email to