def test_downloadPageLogsFileCloseError(self):
        """
        If there is an exception closing the file being written to after the
        connection is prematurely closed, that exception is logged.
        """
        exc = IOError(ENOSPC, "No file left on device")

        class BrokenFile:
            def write(self, bytes):
                pass

            def close(self):
                raise exc

        logObserver = EventLoggingObserver()
        filtered = FilteringLogObserver(
            logObserver,
            [LogLevelFilterPredicate(defaultLogLevel=LogLevel.critical)]
        )
        globalLogPublisher.addObserver(filtered)
        self.addCleanup(lambda: globalLogPublisher.removeObserver(filtered))

        d = client.downloadPage(self.getURL("broken"), BrokenFile())
        d = self.assertFailure(d, client.PartialDownloadError)

        def cbFailed(ignored):
            self.assertEquals(1, len(logObserver))
            event = logObserver[0]
            f = event["log_failure"]
            self.assertIsInstance(f.value, IOError)
            self.assertEquals(
                f.value.args,
                exc.args
            )
            self.assertEqual(len(self.flushLoggedErrors(IOError)), 1)

        d.addCallback(cbFailed)
        return d

        If there is an exception closing the file being written to after the
        connection is prematurely closed, that exception is logged.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/web/test/test_webclient.py