'Obtains the current session variables.
Backported the else clause from Django 1.7 to make sure there
is a session available during tests.'

def _session(self):

    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)
        else:
            session = engine.SessionStore()
            session.save()
            self.cookies[settings.SESSION_COOKIE_NAME] = session.session_key
            return session
    return {}
