code: def test_watch_app_state():
      """We can watch the App state and a callback function will be run when it changes."""
      callback = mock.MagicMock()
      # When
      _watch_app_state(callback)
  
      # Here we would like to send messages using the web socket
      # For testing the web socket is not started. See conftest.py
      # So we need to manually trigger _run_callbacks here
      _run_callbacks()
      # Then
      callback.assert_called_once()
  
file_path: pytorch-lightning/tests/tests_app/frontend/panel/test_app_state_comm.py
imports: import os
  from unittest import mock
  from lightning.app.core.constants import APP_SERVER_PORT
  from lightning.app.frontend.panel.app_state_comm import _get_ws_url, _run_callbacks, _watch_app_state
label_desc: Use image node_id 4 for calling a global function with example usage: test_watch_app_state() without return types