code: def test_connect_disconnect_local(tmpdir, monkeypatch):
      disconnect_app()
  
      with pytest.raises(
          Exception,
          match="Connection wasn't successful. Is your app localhost running ?",
      ):
          connect_app("localhost")
  
      with open(
          os.path.join(
              os.path.dirname(__file__), "jsons/connect_1.json"
          )
      ) as f:
          data = json.load(f)
  
      data["paths"]["/command/command_with_client"]["post"][
          "cls_path"
      ] = os.path.join(
          _PROJECT_ROOT,
          data["paths"]["/command/command_with_client"]["post"][
              "cls_path"
          ],
      )
  
      messages = []
  
      disconnect_app()
  
      def fn(msg):
          messages.append(msg)
  
      monkeypatch.setattr(click, "echo", fn)
  
      response = MagicMock()
      response.status_code = 200
      response.json.return_value = data
      monkeypatch.setattr(
          cli_helpers.requests, "get", MagicMock(return_value=response)
      )
      connect_app("localhost")
      assert _retrieve_connection_to_an_app() == ("localhost", None)
      command_path = _resolve_command_path("nested_command")
      assert not os.path.exists(command_path)
      command_path = _resolve_command_path("command_with_client")
      assert os.path.exists(command_path)
      messages = []
      connect_app("localhost")
      assert messages == [
          "You are connected to the local Lightning App."
      ]
  
      messages = []
      disconnect_app()
      assert messages == [
          "You are disconnected from the local Lightning App."
      ]
      messages = []
      disconnect_app()
      assert messages == [
          "You aren't connected to any Lightning App. Please use `lightning connect app_name_or_id` to connect to one."
      ]
  
      assert _retrieve_connection_to_an_app() == (None, None)
  
file_path: pytorch-lightning/tests/tests_app/cli/test_connect.py
imports: import json
  import os
  from unittest.mock import MagicMock
  import click
  import psutil
  import pytest
  from lightning.app import _PROJECT_ROOT
  from lightning.app.cli.connect.app import _list_app_commands, _resolve_command_path, _retrieve_connection_to_an_app, connect_app, disconnect_app
  from lightning.app.utilities import cli_helpers
  from lightning.app.utilities.commands import base
label_desc: Use image node_id 2 for calling a global function with example usage: test_connect_disconnect_local(tmpdir, monkeypatch) without return types