#31299: DB not flushed between TestCases
-------------------------------------+-------------------------------------
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 |
-------------------------------------+-------------------------------------
Consider the case where I have two fixtures and two different TestCase
classes that use them.
**fixture1.json**
{{{
[
{
"model": "app1.user",
"pk": 1,
"fields": {
"password": "",
"last_login": null,
"is_superuser": false,
"username": "tesuser1",
"first_name": "",
"last_name": "",
"is_staff": false,
"is_active": true,
"date_joined": "2020-02-21T12:59:17.302Z",
"email": null,
"groups": [],
"user_permissions": []
}
}
]
}}}
**fixture2.json**
{{{
[
{
"model": "app1.user",
"pk": 2,
"fields": {
"password": "",
"last_login": null,
"is_superuser": false,
"username": "testuser2",
"first_name": "",
"last_name": "",
"is_staff": false,
"is_active": true,
"date_joined": "2020-02-21T12:59:17.302Z",
"email": null,
"groups": [],
"user_permissions": []
}
}
]
}}}
**Here are my test cases**
{{{
class Test1(TestCase):
fixtures = ['fixture1.json']
@classmethod
def tearDownClass(cls):
super(TestCase, cls).tearDownClass()
def test_demo(self):
u = User.objects.get(username='testuser1')
#some testing
class Test2(TestCase):
fixtures = ['fixture2.json']
@classmethod
def tearDownClass(cls):
super(TestCase, cls).tearDownClass()
def test_demo2(self):
try:
u = User.objects.get(username='testuser1')
print("Found him")
#Some testing
except:
pass
}}}
I wouldn't expect to find testuser1 in my second test case as the fixtures
for it doesn't have that particular user.
**From django documentation:**
At the start of each test, before setUp() is run, Django will flush the
database, returning the database to the state it was in directly after
migrate was called.
--
Ticket URL: <https://code.djangoproject.com/ticket/31299>
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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/055.2686cd5c849f7279bd59bc399bc6ece4%40djangoproject.com.