import warnings


def force_connect(client):
    """
    Convenience to wait for a newly-constructed client to connect.
    Taken from pymongo test.utils.connected.
    """

    with warnings.catch_warnings():
        # Ignore warning that "ismaster" is always routed to primary even
        # if client's read preference isn't PRIMARY.
        warnings.simplefilter("ignore", UserWarning)
        client.admin.command("ismaster")  # Force connection.

    return client