def figure_context(*args, **kwargs):
    """context manager which autocloses a figure (even if the test failed)"""

    try:
        yield None
    finally:
        plt.close("all")
context manager which autocloses a figure (even if the test failed)
xarray/tests/test_plot.py