def test_doesntBleed(self):
        """
        Forcing garbage collection in the test should mean that there are
        no unreachable cycles immediately after the test completes.
        """
        result = reporter.TestResult()
        self.test1(result)
        self.flushLoggedErrors() # test1 logs errors that get caught be us.
        # test1 created unreachable cycle.
        # it & all others should have been collected by now.
        if _PY3:
            n = len(gc.garbage)
        else:
            n = gc.collect()
        self.assertEqual(n, 0, 'unreachable cycle still existed')
        # check that last gc.collect didn't log more errors
        x = self.flushLoggedErrors()
        self.assertEqual(len(x), 0, 'Errors logged after gc.collect')

        Forcing garbage collection in the test should mean that there are
        no unreachable cycles immediately after the test completes.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/trial/test/test_tests.py