Index: test/client.py
===================================================================
--- test/client.py	(revision 10620)
+++ test/client.py	(working copy)
@@ -166,6 +166,7 @@ class Client(object):
         self.cookies = SimpleCookie()
         self.exc_info = None
         self.errors = StringIO()
+        self._session_cache = None
 
     def store_exc_info(self, **kwargs):
         """
@@ -177,12 +178,24 @@ class Client(object):
         """
         Obtains the current session variables.
         """
-        if 'django.contrib.sessions' in settings.INSTALLED_APPS:
-            engine = import_module(settings.SESSION_ENGINE)
-            cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None)
-            if cookie:
-                return engine.SessionStore(cookie.value)
-        return {}
+        if self._session_cache == None:
+            if 'django.contrib.sessions' in settings.INSTALLED_APPS:
+                engine = import_module(settings.SESSION_ENGINE)
+                cookie = self.cookies.get(settings.SESSION_COOKIE_NAME, None)
+                if cookie:
+                    self._session_cache = engine.SessionStore(cookie.value)
+                else:
+                    self._session_cache = engine.SessionStore()
+                    self._session_cache.save()  # make load() work so the cookie isn't worthless
+                    self.cookies[settings.SESSION_COOKIE_NAME] = self._session_cache.session_key
+            else:
+                self._session_cache = {}
+        return self._session_cache
+    def _session_save(self):
+        if self._session_cache:
+            self._session_cache.save()
+            self._session_cache = None
+
     session = property(_session)
 
     def request(self, **request):
@@ -268,6 +281,7 @@ class Client(object):
         """
         Requests a response from the server using GET.
         """
+        self._session_save()
         parsed = urlparse(path)
         r = {
             'CONTENT_TYPE':    'text/html; charset=utf-8',
@@ -288,6 +302,7 @@ class Client(object):
         """
         Requests a response from the server using POST.
         """
+        self._session_save()
         if content_type is MULTIPART_CONTENT:
             post_data = encode_multipart(BOUNDARY, data)
         else:
@@ -319,6 +334,7 @@ class Client(object):
         """
         Request a response from the server using HEAD.
         """
+        self._session_save()
         parsed = urlparse(path)
         r = {
             'CONTENT_TYPE':    'text/html; charset=utf-8',
@@ -338,6 +354,7 @@ class Client(object):
         """
         Request a response from the server using OPTIONS.
         """
+        self._session_save()
         parsed = urlparse(path)
         r = {
             'PATH_INFO':       urllib.unquote(parsed[2]),
@@ -357,6 +374,7 @@ class Client(object):
         """
         Send a resource to the server using PUT.
         """
+        self._session_save()
         if content_type is MULTIPART_CONTENT:
             post_data = encode_multipart(BOUNDARY, data)
         else:
@@ -382,6 +400,7 @@ class Client(object):
         """
         Send a DELETE request to the server.
         """
+        self._session_save()
         parsed = urlparse(path)
         r = {
             'PATH_INFO':       urllib.unquote(parsed[2]),
@@ -404,6 +423,7 @@ class Client(object):
         are incorrect, or the user is inactive, or if the sessions framework is
         not available.
         """
+        self._session_save()
         user = authenticate(**credentials)
         if user and user.is_active \
                 and 'django.contrib.sessions' in settings.INSTALLED_APPS:
@@ -442,6 +462,7 @@ class Client(object):
 
         Causes the authenticated user to be logged out.
         """
+        self._session_cache = None
         session = import_module(settings.SESSION_ENGINE).SessionStore()
         session_cookie = self.cookies.get(settings.SESSION_COOKIE_NAME)
         if session_cookie:
