code: def mpl_test_cleanup(request):
      """Run tests in a context manager and close figures after each test."""
      with ExitStack() as stack:
          # At exit, close all open figures and switch backend back to original.
          stack.callback(plt.switch_backend, plt.get_backend())
          stack.callback(plt.close, "all")
  
          # Run each test in a context manager so that state does not leak out
          plt.switch_backend("Agg")
          stack.enter_context(plt.rc_context())
          yield
  
imports: from contextlib import ExitStack
  import matplotlib.pyplot
  import pytest
label_desc: Use image node_id 1 for calling a global function with example usage: mpl_test_cleanup(request) without return types