code: def test_lightning_run_app(
      lauch_mock: mock.MagicMock, open_ui, caplog, monkeypatch
  ):
      """This test validates the command is runned properly and the LightningApp method is being executed."""
      monkeypatch.setattr("lightning.app._logger", logging.getLogger())
  
      original_method = LightningApp._run
  
      @convert_print_to_logger_info
      def _lightning_app_run_and_logging(self, *args, **kwargs):
          original_method(self, *args, **kwargs)
          print("1" if open_ui else "0")
          print(self)
  
      with caplog.at_level(logging.INFO):
          with mock.patch(
              "lightning.app.LightningApp._run",
              _lightning_app_run_and_logging,
          ):
              runner = CliRunner()
              pytest_env = os.environ.pop("PYTEST_CURRENT_TEST")
              try:
                  result = runner.invoke(
                      run_app,
                      [
                          os.path.join(
                              _PROJECT_ROOT,
                              "tests/tests_app/core/scripts/app_metadata.py",
                          ),
                          "--blocking",
                          "False",
                          "--open-ui",
                          str(open_ui),
                      ],
                      catch_exceptions=False,
                  )
              finally:
                  os.environ["PYTEST_CURRENT_TEST"] = pytest_env
              # capture logs.
              if open_ui:
                  # Get the designated port
                  port = constants.APP_SERVER_PORT
  
                  lauch_mock.assert_called_with(
                      f"http://127.0.0.1:{port}/view"
                  )
              else:
                  lauch_mock.assert_not_called()
          assert result.exit_code == 0
      assert len(caplog.messages) == 4
      assert bool(int(caplog.messages[0])) is open_ui
  
file_path: pytorch-lightning/tests/tests_app/cli/test_run_app.py
imports: import logging
  import os
  from pathlib import Path
  from unittest import mock
  import click
  import lightning.app.core.constants
  import pytest
  from click.testing import CliRunner
  from lightning.app import LightningApp
  from lightning.app.cli.lightning_cli import _run_app, run_app
  from lightning.app.runners.runtime_type import RuntimeType
  from lightning.app.utilities.app_helpers import convert_print_to_logger_info
  from tests_app import _PROJECT_ROOT
label_desc: Use image node_id 1 for calling a global function with example usage: test_lightning_run_app(lauch_mock, open_ui, caplog, monkeypatch) without return types