code: def monkeypatch_connection(monkeypatch, tmpdir, ppid):
      connection_path = os.path.join(tmpdir, ppid)
      monkeypatch.setattr(
          "lightning.app.cli.connect.app._clean_lightning_connection",
          MagicMock(),
      )
      monkeypatch.setattr("lightning.app.cli.connect.app._PPID", ppid)
      monkeypatch.setattr(
          "lightning.app.cli.connect.app._LIGHTNING_CONNECTION", tmpdir
      )
      monkeypatch.setattr(
          "lightning.app.cli.connect.app._LIGHTNING_CONNECTION_FOLDER",
          connection_path,
      )
      return connection_path
  
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 1 for calling a global function with example usage: monkeypatch_connection(monkeypatch, tmpdir, ppid) and returns: connection_path