code: def test_launch_supplied_logfile(
      runner, monkeypatch, caplog, wandb_init, test_settings
  ):
      """Test that the logfile is set properly when supplied via the CLI."""
  
      def patched_pop_empty_queue(self, queue):
          # patch to no result, agent should read stopPolling and stop
          return None
  
      _setup_agent(monkeypatch, patched_pop_empty_queue)
  
      monkeypatch.setattr(
          "wandb.sdk.internal.internal_api.Api.get_launch_agent",
          lambda c, i, g: {
              "id": "mock_agent_id",
              "name": "blah",
              "stopPolling": True,
          },
      )
      monkeypatch.setattr(
          "wandb.sdk.internal.internal_api.Api.update_launch_agent_status",
          lambda c, i, s, g: {"success": True},
      )
  
      with runner.isolated_filesystem():
          with caplog.at_level("INFO"):
              result = runner.invoke(
                  cli.launch_agent,
                  [
                      "--queue=default",
                      "--log-file=agent.logs",
                  ],
              )
  
              assert (
                  "Internal agent logs printing to agent.logs"
                  in result.output
              )
  
              print("Output from cli command:")
              print(result.output)
  
              # open agent logs and inspect the contents
              with open("agent.logs") as f:
                  logs = f.read()
                  print("agent.logs:")
                  print(logs)
                  assert (
                      "Internal agent logs printing to agent.logs"
                      in logs
                  )
  
              assert result.exit_code == 0
  
imports: import json
  from unittest.mock import Mock
  import pytest
  import wandb
  from wandb.cli import cli
  from wandb.sdk.launch.errors import LaunchError
label_desc: Use image node_id 16 for calling a global function with example usage: test_launch_supplied_logfile(runner, monkeypatch, caplog, wandb_init, test_settings) and returns: None