code: def pytest_collection_modifyitems(session, config, items):
      # look for all those classes that specify __backend__ and
      # expand them out into per-database test cases.
  
      # this is much easier to do within pytest_pycollect_makeitem, however
      # pytest is iterating through cls.__dict__ as makeitem is
      # called which causes a "dictionary changed size" error on py3k.
      # I'd submit a pullreq for them to turn it into a list first, but
      # it's to suit the rather odd use case here which is that we are adding
      # new classes to a module on the fly.
  
      from sqlalchemy.testing import asyncio
  
      rebuilt_items = collections.defaultdict(
          lambda: collections.defaultdict(list)
      )
  
      items[:] = [
          item
          for item in items
          if item.getparent(pytest.Class) is not None
          and not item.getparent(pytest.Class).name.startswith("_")
      ]
  
      test_classes = {item.getparent(pytest.Class) for item in items}
  
      def collect(element):
          for inst_or_fn in element.collect():
              if isinstance(inst_or_fn, pytest.Collector):
                  yield from collect(inst_or_fn)
              else:
                  yield inst_or_fn
  
      def setup_test_classes():
          for test_class in test_classes:
              # transfer legacy __backend__ and __sparse_backend__ symbols
              # to be markers
              add_markers = set()
              if getattr(
                  test_class.cls, "__backend__", False
              ) or getattr(test_class.cls, "__only_on__", False):
                  add_markers = {"backend"}
              elif getattr(test_class.cls, "__sparse_backend__", False):
                  add_markers = {"sparse_backend"}
              else:
                  add_markers = frozenset()
  
              existing_markers = {
                  mark.name for mark in test_class.iter_markers()
              }
              add_markers = add_markers - existing_markers
              all_markers = existing_markers.union(add_markers)
  
              for marker in add_markers:
                  test_class.add_marker(marker)
  
              for sub_cls in plugin_base.generate_sub_tests(
                  test_class.cls, test_class.module, all_markers
              ):
                  if sub_cls is not test_class.cls:
                      per_cls_dict = rebuilt_items[test_class.cls]
  
                      module = test_class.getparent(pytest.Module)
  
                      new_cls = pytest.Class.from_parent(
                          name=sub_cls.__name__, parent=module
                      )
                      for marker in add_markers:
                          new_cls.add_marker(marker)
  
                      for fn in collect(new_cls):
                          per_cls_dict[fn.name].append(fn)
  
      # class requirements will sometimes need to access the DB to check
      # capabilities, so need to do this for async
      asyncio._maybe_async_provisioning(setup_test_classes)
  
      newitems = []
      for item in items:
          cls_ = item.cls
          if cls_ in rebuilt_items:
              newitems.extend(rebuilt_items[cls_][item.name])
          else:
              newitems.append(item)
  
      # seems like the functions attached to a test class aren't sorted already?
      # is that true and why's that? (when using unittest, they're sorted)
      items[:] = sorted(
          newitems,
          key=lambda item: (
              item.getparent(pytest.Module).name,
              item.getparent(pytest.Class).name,
              item.name,
          ),
      )
  
imports: from __future__ import annotations
  import argparse
  import collections
  from functools import update_wrapper
  import inspect
  import itertools
  import operator
  import os
  import re
  import sys
  from typing import TYPE_CHECKING
  import uuid
  import pytest
label_desc: Use image node_id 9 for calling a global function with example usage: pytest_collection_modifyitems(session, config, items) without return types