code: def _get_all_test_query(
      targets: List[str],
      team: str,
      except_tags: Optional[str] = None,
      only_tags: Optional[str] = None,
  ) -> str:
      """
      Get all test targets that are owned by a particular team, except those that
      have the given tags
      """
      test_query = " union ".join(
          [f"tests({target})" for target in targets]
      )
      query = f"attr(tags, '{_get_tag_matcher(f'team:{team}')}', {test_query})"
  
      if only_tags:
          only_query = " union ".join(
              [
                  f"attr(tags, '{_get_tag_matcher(t)}', {test_query})"
                  for t in only_tags.split(",")
              ]
          )
          query = f"{query} intersect ({only_query})"
  
      if except_tags:
          except_query = " union ".join(
              [
                  f"attr(tags, '{_get_tag_matcher(t)}', {test_query})"
                  for t in except_tags.split(",")
              ]
          )
          query = f"{query} except ({except_query})"
  
      return query
  
file_path: ray/ci/ray_ci/tester.py
imports: import os
  import sys
  from typing import List, Tuple, Optional
  import yaml
  import click
  from ci.ray_ci.container import _DOCKER_ECR_REPO
  from ci.ray_ci.builder_container import BuilderContainer, DEFAULT_BUILD_TYPE, DEFAULT_PYTHON_VERSION, DEFAULT_ARCHITECTURE, PYTHON_VERSIONS
  from ci.ray_ci.linux_tester_container import LinuxTesterContainer
  from ci.ray_ci.windows_tester_container import WindowsTesterContainer
  from ci.ray_ci.tester_container import TesterContainer
  from ci.ray_ci.utils import docker_login
  from ray_release.configs.global_config import init_global_config
  from ray_release.bazel import bazel_runfile
label_desc: Use image node_id 5 for calling a global function with example usage: _get_all_test_query(targets, team, except_tags, only_tags) and returns: query