def test_loseConnection(self):
        """
        Test that loseConnection sends a disconnect message and closes the
        connection.
        """
        disconnected = [False]
        def stubLoseConnection():
            disconnected[0] = True
        self.transport.loseConnection = stubLoseConnection
        self.proto.loseConnection()
        self.assertEqual(self.packets[0][0], transport.MSG_DISCONNECT)
        self.assertEqual(self.packets[0][1][3:4],
                         chr(transport.DISCONNECT_CONNECTION_LOST))

        Test that loseConnection sends a disconnect message and closes the
        connection.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/conch/test/test_transport.py