code: def test_importlib_plugins(
      tmp_path,
      flake8_dist,
      flake8_foo_dist,
      mock_distribution,
      caplog,
  ):
      """Ensure we can load plugins from importlib.metadata."""
  
      # make sure flake8-colors is skipped
      flake8_colors_metadata = """\
  Metadata-Version: 2.1
  Name: flake8-colors
  Version: 1.2.3
  """
      flake8_colors_eps = """\
  [flake8.extension]
  flake8-colors = flake8_colors:ColorFormatter
  """
      flake8_colors_d = tmp_path.joinpath("flake8_colors.dist-info")
      flake8_colors_d.mkdir()
      flake8_colors_d.joinpath("METADATA").write_text(
          flake8_colors_metadata
      )
      flake8_colors_d.joinpath("entry_points.txt").write_text(
          flake8_colors_eps
      )
      flake8_colors_dist = importlib.metadata.PathDistribution(
          flake8_colors_d
      )
  
      unrelated_metadata = """\
  Metadata-Version: 2.1
  Name: unrelated
  Version: 4.5.6
  """
      unrelated_eps = """\
  [console_scripts]
  unrelated = unrelated:main
  """
      unrelated_d = tmp_path.joinpath("unrelated.dist-info")
      unrelated_d.mkdir()
      unrelated_d.joinpath("METADATA").write_text(unrelated_metadata)
      unrelated_d.joinpath("entry_points.txt").write_text(unrelated_eps)
      unrelated_dist = importlib.metadata.PathDistribution(unrelated_d)
  
      with mock.patch.object(
          importlib.metadata,
          "distributions",
          return_value=[
              flake8_dist,
              flake8_colors_dist,
              flake8_foo_dist,
              unrelated_dist,
          ],
      ):
          ret = set(finder._find_importlib_plugins())
  
      assert ret == {
          finder.Plugin(
              "flake8-foo",
              "1.2.3",
              importlib.metadata.EntryPoint(
                  "Q", "flake8_foo:Plugin", "flake8.extension"
              ),
          ),
          finder.Plugin(
              "pycodestyle",
              "9000.2.0",
              importlib.metadata.EntryPoint(
                  "E",
                  "flake8.plugins.pycodestyle:pycodestyle_logical",
                  "flake8.extension",
              ),
          ),
          finder.Plugin(
              "pycodestyle",
              "9000.2.0",
              importlib.metadata.EntryPoint(
                  "W",
                  "flake8.plugins.pycodestyle:pycodestyle_physical",
                  "flake8.extension",
              ),
          ),
          finder.Plugin(
              "pyflakes",
              "9000.1.0",
              importlib.metadata.EntryPoint(
                  "F",
                  "flake8.plugins.pyflakes:FlakesChecker",
                  "flake8.extension",
              ),
          ),
          finder.Plugin(
              "flake8",
              "9001",
              importlib.metadata.EntryPoint(
                  "default",
                  "flake8.formatting.default:Default",
                  "flake8.report",
              ),
          ),
          finder.Plugin(
              "flake8",
              "9001",
              importlib.metadata.EntryPoint(
                  "pylint",
                  "flake8.formatting.default:Pylint",
                  "flake8.report",
              ),
          ),
          finder.Plugin(
              "flake8-foo",
              "1.2.3",
              importlib.metadata.EntryPoint(
                  "foo", "flake8_foo:Formatter", "flake8.report"
              ),
          ),
      }
  
      assert caplog.record_tuples == [
          (
              "flake8.plugins.finder",
              30,
              "flake8-colors plugin is obsolete in flake8>=5.0",
          ),
      ]
  
imports: from __future__ import annotations
  import configparser
  import importlib.metadata
  import sys
  from unittest import mock
  import pytest
  from flake8.exceptions import ExecutionError
  from flake8.exceptions import FailedToLoadPlugin
  from flake8.plugins import finder
  from flake8.plugins.pyflakes import FlakesChecker
label_desc: Use image node_id 13 for calling a global function with example usage: test_importlib_plugins(tmp_path, flake8_dist, flake8_foo_dist, mock_distribution, caplog) without return types