async def test_build_fail(app, needs_build, needs_launch, always_build):
    """
    Test build a repo that should fail immediately.
    """
    slug = "gh/binderhub-ci-repos/minimal-dockerfile/failed"
    build_url = f"{app.url}/build/{slug}"
    r = await async_requests.get(build_url, stream=True)
    r.raise_for_status()
    failed_events = 0
    async for line in async_requests.iter_lines(r):
        line = line.decode("utf8", "replace")
        if line.startswith("data:"):
            event = json.loads(line.split(":", 1)[1])
            assert event.get("phase") not in ("launching", "ready")
            if event.get("phase") == "failed":
                failed_events += 1
                break
    r.close()

    assert failed_events > 0, "Should have seen phase 'failed'"

    Test build a repo that should fail immediately.
    
binderhub/tests/test_build.py