'Get the only message in self.messages.
Raises ValueError if there are multiple or no messages.
Args:
level: The message level to check against, or None.'

def getmsg(self, level=None):

    assert (len(self.messages) == 1)
    msg = self.messages[0]
    if (level is not None):
        assert (msg.level == level)
    return msg
