def assert_succeeds(exception, msg_fmt="{msg}"):
    """Fail if a specific exception is raised within the context.

    This assertion should be used for cases, where successfully running a
    function signals a successful test, and raising the exception of a
    certain type signals a test failure. All other raised exceptions are
    passed on and will usually still result in a test error. This can be
    used to signal the intent of a block.

    >>> l = ["foo", "bar"]
    >>> with assert_succeeds(ValueError):
    ...     i = l.index("foo")
    ...
    >>> with assert_succeeds(ValueError):
    ...     raise ValueError()
    ...
    Traceback (most recent call last):
        ...
    AssertionError: ValueError was unexpectedly raised
    >>> with assert_succeeds(ValueError):
    ...     raise TypeError("Wrong Error")
    ...
    Traceback (most recent call last):
        ...
    TypeError: Wrong Error

    The following msg_fmt arguments are supported:
    * msg - the default error message
    * exc_type - exception type
    * exc_name - exception type name
    * exception - exception that was raised
    """

    class _AssertSucceeds(object):
        def __enter__(self):
            pass

        def __exit__(self, exc_type, exc_val, exc_tb):
            if exc_type and issubclass(exc_type, exception):
                msg = exception.__name__ + " was unexpectedly raised"
                fail(
                    msg_fmt.format(
                        msg=msg,
                        exc_type=exception,
                        exc_name=exception.__name__,
                        exception=exc_val,
                    )
                )

    return _AssertSucceeds()