コード例 #1
0
def get_tyrant_or_SkipTest():
    def emit_no_tyrant_msg(reason):
        global _no_tyrant_msg_emitted
        if not _no_tyrant_msg_emitted:
            sys.stderr.write("\n" + _no_tyrant_msg % reason + "\n")
            _no_tyrant_msg_emitted = True

    if tyrant.pytyrant is None:
        emit_no_tyrant_msg("not installed")
        raise SkipTest("pytyrant library not installed")

    try:
        tb = TyrantBackend()
        try:
            tb.open()
        except socket.error, exc:
            emit_no_tyrant_msg("not running")
            raise SkipTest("Can't connect to Tokyo server: %s" % (exc, ))
        return tb