def _validate_project(project, parent):
    """Ensure the project is set appropriately.

    If ``parent`` is passed, skip the test (it will be checked / fixed up
    later).

    If ``project`` is unset, attempt to infer the project from the environment.

    :type project: string
    :param project: A project.

    :type parent: :class:`gcloud.datastore.key.Key` or ``NoneType``
    :param parent: The parent of the key or ``None``.

    :rtype: string
    :returns: The ``project`` passed in, or implied from the environment.
    :raises: :class:`ValueError` if ``project`` is ``None`` and no project
             can be inferred from the parent.
    """
    if parent is None:
        if project is None:
            raise ValueError('A Key must have a project set.')
    return project
