prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Figure tests directory gets wiped after running via the test runner.
  Just discovered that when I run:
  ```bash
  python setup.py test --figure-only
  ```
  The resulting figure images are saved in a tmp directory that gets wiped at the end of the process (this is under linux for me)
  
  Using `pytest` adds the folder into my sunpy folder.
  
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `sunpy/conftest.py`
  Content:
  ```
  1 from __future__ import absolute_import, print_function
  2 from functools import partial
  3 
  4 import os
  5 import tempfile
  6 import json
  7 
  8 # Force MPL to use non-gui backends for testing.
  9 try:
  10     import matplotlib
  11 except ImportError:
  12     pass
  13 else:
  14     matplotlib.use('Agg')
  15 
  16 from sunpy.tests.hash import HASH_LIBRARY_NAME
  17 from sunpy.tests.helpers import new_hash_library, test_fig_dir
  18 from sunpy.extern import six
  19 
  20 import pytest
  21 
  22 
  23 # Don't actually import pytest_remotedata because that can do things to the
  24 # entrypoints code in pytest.
  25 if six.PY2:
  26     import imp
  27     try:
  28         imp.find_module('pytest_remotedata')
  29         HAVE_REMOTEDATA = True
  30     except ImportError:
  31         HAVE_REMOTEDATA = False
  32 else:
  33     import importlib
  34     remotedata_spec = importlib.util.find_spec("pytest_remotedata")
  35     HAVE_REMOTEDATA = remotedata_spec is not None
  36 
  37 
  38 def pytest_runtest_setup(item):
  39     """
  40     pytest hook to skip all tests that have the mark 'online' if the
  41     client is online (simply detected by checking whether http://www.google.com
  42     can be requested).
  43     """
  44     if isinstance(item, item.Function):
  45         if 'remote_data' in item.keywords and not HAVE_REMOTEDATA:
  46             pytest.skip("skipping remotedata tests as pytest-remotedata is not installed")
  47 
  48 
  49 def pytest_unconfigure(config):
  50     if len(new_hash_library) > 0:
  51         # Write the new hash library in JSON
  52         hashfile = os.path.join(test_fig_dir, HASH_LIBRARY_NAME)
  53         with open(hashfile, 'w') as outfile:
  54             json.dump(new_hash_library, outfile, sort_keys=True, indent=4, separators=(',', ': '))
  55 
  56         print('All images from image tests can be found in {0}'.format(test_fig_dir))
  57         print("The corresponding hash library is {0}".format(hashfile))
  58
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/sunpy/conftest.py b/sunpy/conftest.py
  --- a/sunpy/conftest.py
  +++ b/sunpy/conftest.py
  @@ -13,8 +13,9 @@
   else:
       matplotlib.use('Agg')
   
  +import sunpy.tests.helpers
   from sunpy.tests.hash import HASH_LIBRARY_NAME
  -from sunpy.tests.helpers import new_hash_library, test_fig_dir
  +from sunpy.tests.helpers import new_hash_library
   from sunpy.extern import six
   
   import pytest
  @@ -35,6 +36,15 @@
       HAVE_REMOTEDATA = remotedata_spec is not None
   
   
  +def pytest_addoption(parser):
  +    parser.addoption("--figure_dir", action="store", default="./figure_test_images")
  +
  +
  +@pytest.fixture(scope='session', autouse=True)
  +def figure_base_dir(request):
  +    sunpy.tests.helpers.figure_base_dir = request.config.getoption("--figure_dir")
  +
  +
   def pytest_runtest_setup(item):
       """
       pytest hook to skip all tests that have the mark 'online' if the
  @@ -49,9 +59,10 @@
   def pytest_unconfigure(config):
       if len(new_hash_library) > 0:
           # Write the new hash library in JSON
  -        hashfile = os.path.join(test_fig_dir, HASH_LIBRARY_NAME)
  +        figure_base_dir = os.path.abspath(config.getoption("--figure_dir"))
  +        hashfile = os.path.join(figure_base_dir, HASH_LIBRARY_NAME)
           with open(hashfile, 'w') as outfile:
               json.dump(new_hash_library, outfile, sort_keys=True, indent=4, separators=(',', ': '))
   
  -        print('All images from image tests can be found in {0}'.format(test_fig_dir))
  +        print('All images from image tests can be found in {0}'.format(figure_base_dir))
           print("The corresponding hash library is {0}".format(hashfile))
  
verification_info: {"golden_diff": "diff --git a/sunpy/conftest.py b/sunpy/conftest.py\n--- a/sunpy/conftest.py\n+++ b/sunpy/conftest.py\n@@ -13,8 +13,9 @@\n else:\n     matplotlib.use('Agg')\n \n+import sunpy.tests.helpers\n from sunpy.tests.hash import HASH_LIBRARY_NAME\n-from sunpy.tests.helpers import new_hash_library, test_fig_dir\n+from sunpy.tests.helpers import new_hash_library\n from sunpy.extern import six\n \n import pytest\n@@ -35,6 +36,15 @@\n     HAVE_REMOTEDATA = remotedata_spec is not None\n \n \n+def pytest_addoption(parser):\n+    parser.addoption(\"--figure_dir\", action=\"store\", default=\"./figure_test_images\")\n+\n+\n+@pytest.fixture(scope='session', autouse=True)\n+def figure_base_dir(request):\n+    sunpy.tests.helpers.figure_base_dir = request.config.getoption(\"--figure_dir\")\n+\n+\n def pytest_runtest_setup(item):\n     \"\"\"\n     pytest hook to skip all tests that have the mark 'online' if the\n@@ -49,9 +59,10 @@\n def pytest_unconfigure(config):\n     if len(new_hash_library) > 0:\n         # Write the new hash library in JSON\n-        hashfile = os.path.join(test_fig_dir, HASH_LIBRARY_NAME)\n+        figure_base_dir = os.path.abspath(config.getoption(\"--figure_dir\"))\n+        hashfile = os.path.join(figure_base_dir, HASH_LIBRARY_NAME)\n         with open(hashfile, 'w') as outfile:\n             json.dump(new_hash_library, outfile, sort_keys=True, indent=4, separators=(',', ': '))\n \n-        print('All images from image tests can be found in {0}'.format(test_fig_dir))\n+        print('All images from image tests can be found in {0}'.format(figure_base_dir))\n         print(\"The corresponding hash library is {0}\".format(hashfile))\n", "issue": "Figure tests directory gets wiped after running via the test runner.\nJust discovered that when I run:\r\n```bash\r\npython setup.py test --figure-only\r\n```\r\nThe resulting figure images are saved in a tmp directory that gets wiped at the end of the process (this is under linux for me)\r\n\r\nUsing `pytest` adds the folder into my sunpy folder.\r\n\r\n\n", "before_files": [{"content": "from __future__ import absolute_import, print_function\nfrom functools import partial\n\nimport os\nimport tempfile\nimport json\n\n# Force MPL to use non-gui backends for testing.\ntry:\n    import matplotlib\nexcept ImportError:\n    pass\nelse:\n    matplotlib.use('Agg')\n\nfrom sunpy.tests.hash import HASH_LIBRARY_NAME\nfrom sunpy.tests.helpers import new_hash_library, test_fig_dir\nfrom sunpy.extern import six\n\nimport pytest\n\n\n# Don't actually import pytest_remotedata because that can do things to the\n# entrypoints code in pytest.\nif six.PY2:\n    import imp\n    try:\n        imp.find_module('pytest_remotedata')\n        HAVE_REMOTEDATA = True\n    except ImportError:\n        HAVE_REMOTEDATA = False\nelse:\n    import importlib\n    remotedata_spec = importlib.util.find_spec(\"pytest_remotedata\")\n    HAVE_REMOTEDATA = remotedata_spec is not None\n\n\ndef pytest_runtest_setup(item):\n    \"\"\"\n    pytest hook to skip all tests that have the mark 'online' if the\n    client is online (simply detected by checking whether http://www.google.com\n    can be requested).\n    \"\"\"\n    if isinstance(item, item.Function):\n        if 'remote_data' in item.keywords and not HAVE_REMOTEDATA:\n            pytest.skip(\"skipping remotedata tests as pytest-remotedata is not installed\")\n\n\ndef pytest_unconfigure(config):\n    if len(new_hash_library) > 0:\n        # Write the new hash library in JSON\n        hashfile = os.path.join(test_fig_dir, HASH_LIBRARY_NAME)\n        with open(hashfile, 'w') as outfile:\n            json.dump(new_hash_library, outfile, sort_keys=True, indent=4, separators=(',', ': '))\n\n        print('All images from image tests can be found in {0}'.format(test_fig_dir))\n        print(\"The corresponding hash library is {0}\".format(hashfile))\n", "path": "sunpy/conftest.py"}], "after_files": [{"content": "from __future__ import absolute_import, print_function\nfrom functools import partial\n\nimport os\nimport tempfile\nimport json\n\n# Force MPL to use non-gui backends for testing.\ntry:\n    import matplotlib\nexcept ImportError:\n    pass\nelse:\n    matplotlib.use('Agg')\n\nimport sunpy.tests.helpers\nfrom sunpy.tests.hash import HASH_LIBRARY_NAME\nfrom sunpy.tests.helpers import new_hash_library\nfrom sunpy.extern import six\n\nimport pytest\n\n\n# Don't actually import pytest_remotedata because that can do things to the\n# entrypoints code in pytest.\nif six.PY2:\n    import imp\n    try:\n        imp.find_module('pytest_remotedata')\n        HAVE_REMOTEDATA = True\n    except ImportError:\n        HAVE_REMOTEDATA = False\nelse:\n    import importlib\n    remotedata_spec = importlib.util.find_spec(\"pytest_remotedata\")\n    HAVE_REMOTEDATA = remotedata_spec is not None\n\n\ndef pytest_addoption(parser):\n    parser.addoption(\"--figure_dir\", action=\"store\", default=\"./figure_test_images\")\n\n\n@pytest.fixture(scope='session', autouse=True)\ndef figure_base_dir(request):\n    sunpy.tests.helpers.figure_base_dir = request.config.getoption(\"--figure_dir\")\n\n\ndef pytest_runtest_setup(item):\n    \"\"\"\n    pytest hook to skip all tests that have the mark 'online' if the\n    client is online (simply detected by checking whether http://www.google.com\n    can be requested).\n    \"\"\"\n    if isinstance(item, item.Function):\n        if 'remote_data' in item.keywords and not HAVE_REMOTEDATA:\n            pytest.skip(\"skipping remotedata tests as pytest-remotedata is not installed\")\n\n\ndef pytest_unconfigure(config):\n    if len(new_hash_library) > 0:\n        # Write the new hash library in JSON\n        figure_base_dir = os.path.abspath(config.getoption(\"--figure_dir\"))\n        hashfile = os.path.join(figure_base_dir, HASH_LIBRARY_NAME)\n        with open(hashfile, 'w') as outfile:\n            json.dump(new_hash_library, outfile, sort_keys=True, indent=4, separators=(',', ': '))\n\n        print('All images from image tests can be found in {0}'.format(figure_base_dir))\n        print(\"The corresponding hash library is {0}\".format(hashfile))\n", "path": "sunpy/conftest.py"}]}