@contextlib.contextmanager
def _expect_raises(except_cls, msg=None, check_context=False):
    ec = _ErrorContainer()
    if check_context:
        are_we_already_in_a_traceback = sys.exc_info()[0]
    try:
        (yield ec)
        success = False
    except except_cls as err:
        ec.error = err
        success = True
        if (msg is not None):
            assert re.search(msg, util.text_type(err), re.UNICODE), ('%r !~ %s' % (msg, err))
        if (check_context and (not are_we_already_in_a_traceback)):
            _assert_proper_exception_context(err)
        print(util.text_type(err).encode('utf-8'))
    assert success, 'Callable did not raise an exception'
@contextlib.contextmanager
def _expect_raises(except_cls, msg=None, check_context=False):
    ec = _ErrorContainer()
    if check_context:
        are_we_already_in_a_traceback = sys.exc_info()[0]
    try:
        (yield ec)
        success = False
    except except_cls as err:
        ec.error = err
        success = True
        if (msg is not None):
            assert re.search(msg, util.text_type(err), re.UNICODE), ('%r !~ %s' % (msg, err))
        if (check_context and (not are_we_already_in_a_traceback)):
            _assert_proper_exception_context(err)
        print(util.text_type(err).encode('utf-8'))
    assert success, 'Callable did not raise an exception'