def test_getSessionExpired(self):
        """
        L{Request.getSession} generates a new session when the previous
        session has expired.
        """
        clock = Clock()
        site = server.Site(resource.Resource())
        d = DummyChannel()
        request = server.Request(d, 1)
        request.site = site
        request.sitepath = []

        def sessionFactoryWithClock(site, uid):
            """
            Forward to normal session factory, but inject the clock.

            @param site: The site on which the session is created.
            @type site: L{server.Site}

            @param uid: A unique identifier for the session.
            @type uid: C{bytes}

            @return: A newly created session.
            @rtype: L{server.Session}
            """
            session = sessionFactory(site, uid)
            session._reactor = clock
            return session

        # The site is patch to allow injecting a clock to the session.
        sessionFactory = site.sessionFactory
        site.sessionFactory = sessionFactoryWithClock

        initialSession = request.getSession()

        # When the session is requested after the session timeout,
        # no error is raised and a new session is returned.
        clock.advance(sessionFactory.sessionTimeout)
        newSession = request.getSession()
        self.addCleanup(newSession.expire)

        self.assertIsNot(initialSession, newSession)
        self.assertNotEqual(initialSession.uid, newSession.uid)

        L{Request.getSession} generates a new session when the previous
        session has expired.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_web.py