class_docstr: Control image caching for testing.
  
  Image cache files are named according to ``test_name``.
  Multiple calls to an instance of this class will append
  `_X` to the name after the first one.  That is, files
  ``{test_name}``, ``{test_name}_1``, and ``{test_name}_2``
  will be saved if called 3 times.
  
  Parameters
  ----------
  test_name : str
      Name of test to save.  It is used to define the name of image cache
      file.
  
  cache_dir : str
      Directory for image cache comparisons.
  
  error_value : float, default: 500
      Threshold value for determining if two images are not similar enough in
      a test.
  
  warning_value : float, default: 200
      Threshold value to warn that two images are different but not enough to
      fail the test.
  
  var_error_value : float, default: 1000
      Same as error_value but for high variance tests.
  
  var_warning_value : float, default 1000
      Same as warning_value but for high variance tests.
  
  generated_image_dir : str, optional
      Directory to save generated images.  If not specified, no generated
      images are saved.
  
  Examples
  --------
  Create an image cache directory named image_cache and check a simple
  plotter against it. Since ``image_cache`` doesn't exist, it will be created
  and basic.png will be added to it. Subsequent calls to ``verif`` will
  compare the plotter against the cached image.
  
  >>> import pyvista as pv
  >>> from pytest_pyvista import VerifyImageCache
  >>> pl = pv.Plotter(off_screen=True)
  >>> pl.add_mesh(pv.Sphere())
  >>> verif = VerifyImageCache('test_basic', 'image_cache')
  >>> verif(pl)
docstr: Either store or validate an image.
  
  Parameters
  ----------
  plotter : pyvista.Plotter
      The Plotter object that is being closed.
docstr_tok: ["Either","store","or","validate","an","image",".","Parameters","--","--","--","--","--","plotter",":","pyvista.Plotter","The","Plotter","object","that","is","being","closed","."]
code: def __call__(self, plotter):
      """Either store or validate an image.
  
      Parameters
      ----------
      plotter : pyvista.Plotter
          The Plotter object that is being closed.
  
      """
      if self.skip:
          return
  
      if self.ignore_image_cache:
          return
  
      if self.n_calls > 0:
          test_name = f"{self.test_name}_{self.n_calls}"
      else:
          test_name = self.test_name
      self.n_calls += 1
  
      if self.high_variance_test:
          allowed_error = self.var_error_value
          allowed_warning = self.var_warning_value
      else:
          allowed_error = self.error_value
          allowed_warning = self.warning_value
  
      # some tests fail when on Windows with OSMesa
      if os.name == "nt" and self.windows_skip_image_cache:
          return
      # high variation for MacOS
      if platform.system() == "Darwin" and self.macos_skip_image_cache:
          return
  
      # cached image name. We remove the first 5 characters of the function name
      # "test_" to get the name for the image.
      image_name = test_name[5:] + ".png"
      image_filename = os.path.join(self.cache_dir, image_name)
  
      if (
          not os.path.isfile(image_filename)
          and self.fail_extra_image_cache
          and not self.reset_image_cache
      ):
          # Make sure this doesn't get called again if this plotter doesn't close properly
          plotter._before_close_callback = None
          raise RegressionFileNotFound(
              f"{image_filename} does not exist in image cache"
          )
  
      if (
          self.add_missing_images
          and not os.path.isfile(image_filename)
          or self.reset_image_cache
      ) and not self.reset_only_failed:
          plotter.screenshot(image_filename)
  
      if self.generated_image_dir is not None:
          gen_image_filename = os.path.join(
              self.generated_image_dir, test_name[5:] + ".png"
          )
          plotter.screenshot(gen_image_filename)
  
      error = pyvista.compare_images(image_filename, plotter)
  
      if error > allowed_error:
          if self.reset_only_failed:
              warnings.warn(
                  f"{test_name} Exceeded image regression error of "
                  f"{allowed_error} with an image error equal to: {error}"
                  f"\nThis image will be reset in the cache."
              )
              plotter.screenshot(image_filename)
          else:
              # Make sure this doesn't get called again if this plotter doesn't close properly
              plotter._before_close_callback = None
              raise RegressionError(
                  f"{test_name} Exceeded image regression error of "
                  f"{allowed_error} with an image error equal to: {error}"
              )
      if error > allowed_warning:
          warnings.warn(
              f"{test_name} Exceeded image regression warning of "
              f"{allowed_warning} with an image error of "
              f"{error}"
          )
  
file_path: pytest-pyvista/pytest_pyvista/pytest_pyvista.py
imports: import os
  import platform
  import warnings
  import pytest
  import pyvista
label_desc: Use image node_id 2 for calling the VerifyImageCache obj's underlying member method code with example usage: obj.__call__(plotter) without return types