code: def connect():
      @contextmanager
      def _connect(demo: gr.Blocks, serialize=True):
          _, local_url, _ = demo.launch(prevent_thread_lock=True)
          try:
              yield Client(local_url, serialize=serialize)
          finally:
              # A more verbose version of .close()
              # because we should set a timeout
              # the tests that call .cancel() can get stuck
              # waiting for the thread to join
              demo._queue.close()
              demo.is_running = False
              demo.server.should_exit = True
              demo.server.thread.join(timeout=1)
  
      return _connect
  
file_path: gradio/test/conftest.py
imports: import inspect
  import pathlib
  from contextlib import contextmanager
  import pytest
  from gradio_client import Client
  import gradio
label_desc: Use image node_id 4 for calling a global function with example usage: connect() and returns: _connect