code: def _pytest_image_comparison(
      baseline_images,
      extensions,
      tol,
      freetype_version,
      remove_text,
      savefig_kwargs,
      style,
  ):
      """
      Decorate function with image comparison for pytest.
  
      This function creates a decorator that wraps a figure-generating function
      with image comparison code. Pytest can become confused if we change the
      signature of the function, so we indirectly pass anything we need via the
      `mpl_image_comparison_parameters` fixture and extra markers.
      """
      import pytest
  
      extensions = map(
          _mark_xfail_if_format_is_uncomparable, extensions
      )
  
      def decorator(func):
          # Parameter indirection; see docstring above and comment below.
          @pytest.mark.usefixtures("mpl_image_comparison_parameters")
          @pytest.mark.parametrize("extension", extensions)
          @pytest.mark.baseline_images(baseline_images)
          # END Parameter indirection.
          @pytest.mark.style(style)
          @_checked_on_freetype_version(freetype_version)
          @functools.wraps(func)
          def wrapper(*args, **kwargs):
              __tracebackhide__ = True
              img = _ImageComparisonBase(
                  tol=tol,
                  remove_text=remove_text,
                  savefig_kwargs=savefig_kwargs,
              )
              img.delayed_init(func)
              matplotlib.testing.set_font_settings_for_testing()
              func(*args, **kwargs)
  
              # Parameter indirection:
              # This is hacked on via the mpl_image_comparison_parameters fixture
              # so that we don't need to modify the function's real signature for
              # any parametrization. Modifying the signature is very very tricky
              # and likely to confuse pytest.
              baseline_images, extension = func.parameters
  
              assert len(plt.get_fignums()) == len(
                  baseline_images
              ), "Test generated {} images but there are {} baseline images".format(
                  len(plt.get_fignums()), len(baseline_images)
              )
              for idx, baseline in enumerate(baseline_images):
                  img.compare(idx, baseline, extension)
  
          wrapper.__wrapped__ = func  # For Python 2.7.
          return _copy_metadata(func, wrapper)
  
      return decorator
  
imports: from __future__ import absolute_import, division, print_function
  import six
  import functools
  import inspect
  import os
  import sys
  import shutil
  import warnings
  import unittest
  import matplotlib
  import matplotlib.style
  import matplotlib.units
  import matplotlib.testing
  from matplotlib import cbook
  from matplotlib import ticker
  from matplotlib import pyplot
  from matplotlib import ft2font
  from matplotlib.testing.compare import comparable_formats, compare_images, make_test_filename
  from .None import _copy_metadata, is_called_from_pytest
  from .exceptions import ImageComparisonFailure
label_desc: Use image node_id 11 for calling a global function with example usage: _pytest_image_comparison(baseline_images, extensions, tol, freetype_version, remove_text, savefig_kwargs, style) and returns: decorator, _copy_metadata