def METHOD_NAME(
    event_loop: asyncio.AbstractEventLoop,
    unused_tcp_port_factory,
    aiohttp_client,
    api_version_prefix,
    mock_environment: None,
):
    routes = web.RouteTableDef()
    @routes.get("/error")
    async def unexpected_error(request: web.Request):
        msg = "boom shall produce 500"
        raise Exception(msg)  # pylint: disable=broad-exception-raised
    @routes.get(r"/fail")
    async def expected_failure(request: web.Request):
        raise web.HTTPServiceUnavailable
    @routes.get(r"/slow")
    async def blocking_slow(request: web.Request):
        time.sleep(SLOW_HANDLER_DELAY_SECS * 1.1)
        return web.json_response({"data": True, "error": None})
    @routes.get(r"/cancel")
    async def cancelled_task(request: web.Request):
        task: asyncio.Task = request.app.loop.create_task(asyncio.sleep(10))
        task.cancel()  # raise CancelledError
    @routes.get(r"/timeout/{secs}")
    async def time_out(request: web.Request):
        secs = float(request.match_info.get("secs", 0))
        await asyncio.wait_for(
            asyncio.sleep(10 * secs), timeout=secs
        )  # raises TimeOutError
    @routes.get(r"/delay/{secs}")
    async def delay_response(request: web.Request):
        secs = float(request.match_info.get("secs", 0))
        await asyncio.sleep(secs)  # non-blocking slow
        return web.json_response({"data": True, "error": None})
    # -----
    main = {"port": unused_tcp_port_factory(), "host": "localhost"}
    cfg = {
        "main": main,
        "rest": {"enabled": True, "version": api_version_prefix},
        "diagnostics": {"enabled": True},
    }
    app = create_safe_application(cfg)
    # activates some sub-modules
    assert setup_settings(app)
    setup_security(app)
    setup_rest(app)
    setup_diagnostics(app)
    settings: DiagnosticsSettings = app[APP_SETTINGS_KEY].WEBSERVER_DIAGNOSTICS
    assert settings.DIAGNOSTICS_MAX_AVG_LATENCY == 2.0
    app.router.add_routes(routes)
    return event_loop.run_until_complete(
        aiohttp_client(app, server_kwargs={key: main[key] for key in ("host", "port")})
    )