code: def reinitialize_hail_for_each_qob_test(init_hail, request):
      if isinstance(current_backend(), ServiceBackend):
          hl_stop_for_test()
          hl_init_for_test(app_name=request.node.name)
          new_backend = current_backend()
          assert isinstance(new_backend, ServiceBackend)
          yield
          if new_backend._batch_was_submitted:
              batch = new_backend._batch
              report: Dict[str, CollectReport] = request.node.stash[
                  test_results_key
              ]
              if any(r.failed for r in report.values()):
                  log.info(f"cancelling failed test batch {batch.id}")
                  hail_event_loop().run_until_complete(batch.cancel())
      else:
          yield
  
file_path: hail/hail/python/test/hail/conftest.py
imports: from typing import Dict
  import asyncio
  import hashlib
  import os
  import logging
  import pytest
  from pytest import StashKey, CollectReport
  from hail import current_backend, init, reset_global_randomness
  from hail.backend.service_backend import ServiceBackend
  from hailtop.hail_event_loop import hail_event_loop
  from hailtop.utils import secret_alnum_string
  from .helpers import hl_init_for_test, hl_stop_for_test
label_desc: Use image node_id 6 for calling a global function with example usage: reinitialize_hail_for_each_qob_test(init_hail, request) without return types