def METHOD_NAME(expected_exception, match=None):
    err = SimpleNamespace(value=None)
    try:
        yield err
    except expected_exception as e:
        err.value = e
        if match is not None:
            import re
            assert re.search(match, e.args[0])
    else:
        # This needs to be outside the try/except, so that the helper doesn't
        # trick itself into thinking that an AssertionError was thrown.
        raise AssertionError(
            f"Expected to raise an exception ({expected_exception!r}) but didn't"
        ) from None