def safe_repr(obj, short=False):
    _MAX_LENGTH = 80
    try:
        result = repr(obj)
    except Exception:
        result = object.__repr__(obj)
    if not short or len(result) < _MAX_LENGTH:
        return result
    return result[:_MAX_LENGTH] + ' [truncated]...'
Function from python 2.7's unittest.util. Used in methods that is copied 
dataset/ETHPy150Open locustio/locust/locust/test/testcases.py/safe_repr