#24223: SessionMiddleware tests leaving Session objects in database
--------------------------------------+--------------------
Reporter: matt-leach | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Uncategorized | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+--------------------
Currently with default settings several tests in
contrib.sessions.SessionMiddlewareTests leave Session objects remaining in
the database.
This can be seen by adding a tearDown method:
{{{
class SessionMiddlewareTests(unittest.TestCase):
def tearDown(self):
print "Session count:", len(Session.objects.all())
}}}
This results in the following output:
{{{
$ ./manage.py test django.contrib.sessions.tests.SessionMiddlewareTests -v
3
...
test_httponly_session_cookie
(django.contrib.sessions.tests.SessionMiddlewareTests) ... Session count:
1
ok
test_no_httponly_session_cookie
(django.contrib.sessions.tests.SessionMiddlewareTests) ... Session count:
2
ok
test_secure_session_cookie
(django.contrib.sessions.tests.SessionMiddlewareTests) ... Session count:
3
ok
test_session_delete_on_end
(django.contrib.sessions.tests.SessionMiddlewareTests) ... Session count:
3
ok
test_session_save_on_500
(django.contrib.sessions.tests.SessionMiddlewareTests) ... Session count:
4
ok
----------------------------------------------------------------------
Ran 5 tests in 0.011s
OK
}}}
Currently this does not result in failing tests when the test suite is run
but it could lead to issues with tests such as
contrib.sessions.DatabaseSessionTests.test_clearsessions_command:
{{{
class DatabaseSessionTests(SessionTestsMixin, TestCase):
backend = DatabaseSession
...
@override_settings(SESSION_ENGINE="django.contrib.sessions.backends.db")
def test_clearsessions_command(self):
"""
Test clearsessions command for clearing expired sessions.
"""
self.assertEqual(0, Session.objects.count())
}}}
which would fail if run immediately after the SessionMiddleware tests.
I would suggest changing the SessionMiddlewareTests class to inherit from
django.test.TestCase rather than unittest.TestCase which will ensure the
database is flushed after the tests run.
--
Ticket URL: <https://code.djangoproject.com/ticket/24223>
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/053.c72583a501c7db4b7a5d227d76a0df7a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.