We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
[1.0.3] test_print_config_files fails with installed sunpy
<!-- This comments are hidden when you submit the issue so you do not need to remove them!
Please be sure to check out our contributing guidelines: https://github.com/sunpy/sunpy/blob/master/CONTRIBUTING.rst
Please be sure to check out our code of conduct:
https://github.com/sunpy/sunpy/blob/master/CODE_OF_CONDUCT.rst -->

<!-- Please have a search on our GitHub repository to see if a similar issue has already been posted.
If a similar issue is closed, have a quick look to see if you are satisfied by the resolution.
If not please go ahead and open an issue! -->

### Description

On Debian, we run the provided tests regularly on the installed package ("CI test") to ensure that it still works in the current environment. 
With Version 1.0.3 (or before; I didn't check 1.0 … 1.0.2), I see the following failure:

### Actual behavior
`print_test_config_files` tries to write to the installed package, which is denied for an ordinary user:
```
_____________________________________ test_print_config_files _____________________________________

undo_download_dir_patch = None

    def test_print_config_files(undo_download_dir_patch):
        # TODO: Tidy this up.
        stdout = sys.stdout
        out = io.StringIO()
        sys.stdout = out
>       print_config()

/usr/lib/python3/dist-packages/sunpy/util/tests/test_config.py:51: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/usr/lib/python3/dist-packages/sunpy/util/config.py:107: in print_config
    for file_ in _find_config_files():
/usr/lib/python3/dist-packages/sunpy/util/config.py:69: in _find_config_files
    config_path = Path(_get_user_configdir())
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

    def _get_user_configdir():
        """[…]"""
        configdir = os.environ.get('SUNPY_CONFIGDIR', CONFIG_DIR)
    
        if not _is_writable_dir(configdir):
>           raise RuntimeError(f'Could not write to SUNPY_CONFIGDIR="{configdir}"')
E           RuntimeError: Could not write to SUNPY_CONFIGDIR="/usr/lib/python3/dist-packages/sunpy/data"
```
This also happens when I explicitly set `SUNPY_CONFIGDIR` to a different directory; the path mentioned in the `RuntimeError` then still is `/usr/lib/python3/dist-packages/sunpy/data`.

### Steps to Reproduce

```
$ cd /tmp
$ SUNPY_CONFIGDIR=/tmp python3 -c "import sunpy; exit(sunpy.self_test(args=\"-k 'not figure and not online'\"))"
```


### System Details
<!-- We at least need to know the SunPy version you are using. -->
<!-- We provide a short function in SunPy that will provide some of the below information. -->
<!-- It is sunpy.util.system_info(), this is optional but strongly recommended. -->

  - SunPy Version: 1.0.3
  - Astropy Version: 3.2.1
  - Python Version: 3.7.4
  - OS information: Debian unstable


--- 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 import os
2 import json
3 import pathlib
4 import warnings
5 import importlib
6 import tempfile
7 
8 import pytest
9 
10 import astropy
11 import astropy.config.paths
12 
13 import sunpy.tests.helpers
14 from sunpy.tests.hash import HASH_LIBRARY_NAME
15 from sunpy.tests.helpers import new_hash_library, generate_figure_webpage
16 from sunpy.util.exceptions import SunpyDeprecationWarning
17 
18 # Force MPL to use non-gui backends for testing.
19 try:
20     import matplotlib
21 except ImportError:
22     pass
23 else:
24     matplotlib.use('Agg')
25 
26 # Don't actually import pytest_remotedata because that can do things to the
27 # entrypoints code in pytest.
28 remotedata_spec = importlib.util.find_spec("pytest_remotedata")
29 HAVE_REMOTEDATA = remotedata_spec is not None
30 
31 
32 def pytest_addoption(parser):
33     parser.addoption("--figure_dir", action="store", default="./figure_test_images")
34 
35 
36 @pytest.fixture(scope='session', autouse=True)
37 def figure_base_dir(request):
38     sunpy.tests.helpers.figure_base_dir = pathlib.Path(
39         request.config.getoption("--figure_dir"))
40 
41 
42 @pytest.fixture(scope='session', autouse=True)
43 def tmp_config_dir(request):
44     """
45     Globally set the default config for all tests.
46     """
47     tmpdir = tempfile.TemporaryDirectory()
48 
49     os.environ["SUNPY_CONFIGDIR"] = str(pathlib.Path(__file__).parent / "data")
50     astropy.config.paths.set_temp_config._temp_path = str(tmpdir.name)
51     astropy.config.paths.set_temp_cache._temp_path = str(tmpdir.name)
52 
53     yield
54 
55     del os.environ["SUNPY_CONFIGDIR"]
56     astropy.config.paths.set_temp_config._temp_path = None
57     astropy.config.paths.set_temp_cache._temp_path = None
58 
59 
60 @pytest.fixture()
61 def undo_config_dir_patch():
62     """
63     Provide a way for certain tests to not have the config dir.
64     """
65     oridir = os.environ["SUNPY_CONFIGDIR"]
66     del os.environ["SUNPY_CONFIGDIR"]
67     yield
68     os.environ["SUNPY_CONFIGDIR"] = oridir
69 
70 
71 @pytest.fixture(scope='session', autouse=True)
72 def tmp_dl_dir(request):
73     """
74     Globally set the default download directory for the test run to a tmp dir.
75     """
76     with tempfile.TemporaryDirectory() as tmpdir:
77         os.environ["SUNPY_DOWNLOADDIR"] = tmpdir
78         yield tmpdir
79         del os.environ["SUNPY_DOWNLOADDIR"]
80 
81 
82 @pytest.fixture()
83 def undo_download_dir_patch():
84     """
85     Provide a way for certain tests to not have tmp download dir.
86     """
87     oridir = os.environ["SUNPY_DOWNLOADDIR"]
88     del os.environ["SUNPY_DOWNLOADDIR"]
89     yield
90     os.environ["SUNPY_DOWNLOADDIR"] = oridir
91 
92 
93 def pytest_runtest_setup(item):
94     """
95     pytest hook to skip all tests that have the mark 'remotedata' if the
96     pytest_remotedata plugin is not installed.
97     """
98     if isinstance(item, pytest.Function):
99         if 'remote_data' in item.keywords and not HAVE_REMOTEDATA:
100             pytest.skip("skipping remotedata tests as pytest-remotedata is not installed")
101 
102 
103 def pytest_unconfigure(config):
104 
105     # If at least one figure test has been run, print result image directory
106     if len(new_hash_library) > 0:
107         # Write the new hash library in JSON
108         figure_base_dir = pathlib.Path(config.getoption("--figure_dir"))
109         hashfile = figure_base_dir / HASH_LIBRARY_NAME
110         with open(hashfile, 'w') as outfile:
111             json.dump(new_hash_library, outfile, sort_keys=True, indent=4, separators=(',', ': '))
112 
113         """
114         Turn on internet when generating the figure comparison webpage.
115         """
116         if HAVE_REMOTEDATA:
117             from pytest_remotedata.disable_internet import turn_on_internet, turn_off_internet
118         else:
119             def turn_on_internet(): pass
120             def turn_off_internet(): pass
121 
122         turn_on_internet()
123         generate_figure_webpage(new_hash_library)
124         turn_off_internet()
125 
126         print('All images from image tests can be found in {}'.format(figure_base_dir.resolve()))
127         print("The corresponding hash library is {}".format(hashfile.resolve()))
128 
129 
130 def pytest_sessionstart(session):
131     warnings.simplefilter("error", SunpyDeprecationWarning)
132
```
--- 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()

```

diff --git a/sunpy/conftest.py b/sunpy/conftest.py
--- a/sunpy/conftest.py
+++ b/sunpy/conftest.py
@@ -46,7 +46,7 @@
     """
     tmpdir = tempfile.TemporaryDirectory()
 
-    os.environ["SUNPY_CONFIGDIR"] = str(pathlib.Path(__file__).parent / "data")
+    os.environ["SUNPY_CONFIGDIR"] = str(tmpdir.name)
     astropy.config.paths.set_temp_config._temp_path = str(tmpdir.name)
     astropy.config.paths.set_temp_cache._temp_path = str(tmpdir.name)

{"golden_diff": "diff --git a/sunpy/conftest.py b/sunpy/conftest.py\n--- a/sunpy/conftest.py\n+++ b/sunpy/conftest.py\n@@ -46,7 +46,7 @@\n     \"\"\"\n     tmpdir = tempfile.TemporaryDirectory()\n \n-    os.environ[\"SUNPY_CONFIGDIR\"] = str(pathlib.Path(__file__).parent / \"data\")\n+    os.environ[\"SUNPY_CONFIGDIR\"] = str(tmpdir.name)\n     astropy.config.paths.set_temp_config._temp_path = str(tmpdir.name)\n     astropy.config.paths.set_temp_cache._temp_path = str(tmpdir.name)\n", "issue": "[1.0.3] test_print_config_files fails with installed sunpy\n<!-- This comments are hidden when you submit the issue so you do not need to remove them!\r\nPlease be sure to check out our contributing guidelines: https://github.com/sunpy/sunpy/blob/master/CONTRIBUTING.rst\r\nPlease be sure to check out our code of conduct:\r\nhttps://github.com/sunpy/sunpy/blob/master/CODE_OF_CONDUCT.rst -->\r\n\r\n<!-- Please have a search on our GitHub repository to see if a similar issue has already been posted.\r\nIf a similar issue is closed, have a quick look to see if you are satisfied by the resolution.\r\nIf not please go ahead and open an issue! -->\r\n\r\n### Description\r\n\r\nOn Debian, we run the provided tests regularly on the installed package (\"CI test\") to ensure that it still works in the current environment. \r\nWith Version 1.0.3 (or before; I didn't check 1.0 \u2026 1.0.2), I see the following failure:\r\n\r\n### Actual behavior\r\n`print_test_config_files` tries to write to the installed package, which is denied for an ordinary user:\r\n```\r\n_____________________________________ test_print_config_files _____________________________________\r\n\r\nundo_download_dir_patch = None\r\n\r\n    def test_print_config_files(undo_download_dir_patch):\r\n        # TODO: Tidy this up.\r\n        stdout = sys.stdout\r\n        out = io.StringIO()\r\n        sys.stdout = out\r\n>       print_config()\r\n\r\n/usr/lib/python3/dist-packages/sunpy/util/tests/test_config.py:51: \r\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _\r\n/usr/lib/python3/dist-packages/sunpy/util/config.py:107: in print_config\r\n    for file_ in _find_config_files():\r\n/usr/lib/python3/dist-packages/sunpy/util/config.py:69: in _find_config_files\r\n    config_path = Path(_get_user_configdir())\r\n_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _\r\n\r\n    def _get_user_configdir():\r\n        \"\"\"[\u2026]\"\"\"\r\n        configdir = os.environ.get('SUNPY_CONFIGDIR', CONFIG_DIR)\r\n    \r\n        if not _is_writable_dir(configdir):\r\n>           raise RuntimeError(f'Could not write to SUNPY_CONFIGDIR=\"{configdir}\"')\r\nE           RuntimeError: Could not write to SUNPY_CONFIGDIR=\"/usr/lib/python3/dist-packages/sunpy/data\"\r\n```\r\nThis also happens when I explicitly set `SUNPY_CONFIGDIR` to a different directory; the path mentioned in the `RuntimeError` then still is `/usr/lib/python3/dist-packages/sunpy/data`.\r\n\r\n### Steps to Reproduce\r\n\r\n```\r\n$ cd /tmp\r\n$ SUNPY_CONFIGDIR=/tmp python3 -c \"import sunpy; exit(sunpy.self_test(args=\\\"-k 'not figure and not online'\\\"))\"\r\n```\r\n\r\n\r\n### System Details\r\n<!-- We at least need to know the SunPy version you are using. -->\r\n<!-- We provide a short function in SunPy that will provide some of the below information. -->\r\n<!-- It is sunpy.util.system_info(), this is optional but strongly recommended. -->\r\n\r\n  - SunPy Version: 1.0.3\r\n  - Astropy Version: 3.2.1\r\n  - Python Version: 3.7.4\r\n  - OS information: Debian unstable\r\n\n", "before_files": [{"content": "import os\nimport json\nimport pathlib\nimport warnings\nimport importlib\nimport tempfile\n\nimport pytest\n\nimport astropy\nimport astropy.config.paths\n\nimport sunpy.tests.helpers\nfrom sunpy.tests.hash import HASH_LIBRARY_NAME\nfrom sunpy.tests.helpers import new_hash_library, generate_figure_webpage\nfrom sunpy.util.exceptions import SunpyDeprecationWarning\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\n# Don't actually import pytest_remotedata because that can do things to the\n# entrypoints code in pytest.\nremotedata_spec = importlib.util.find_spec(\"pytest_remotedata\")\nHAVE_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 = pathlib.Path(\n        request.config.getoption(\"--figure_dir\"))\n\n\n@pytest.fixture(scope='session', autouse=True)\ndef tmp_config_dir(request):\n    \"\"\"\n    Globally set the default config for all tests.\n    \"\"\"\n    tmpdir = tempfile.TemporaryDirectory()\n\n    os.environ[\"SUNPY_CONFIGDIR\"] = str(pathlib.Path(__file__).parent / \"data\")\n    astropy.config.paths.set_temp_config._temp_path = str(tmpdir.name)\n    astropy.config.paths.set_temp_cache._temp_path = str(tmpdir.name)\n\n    yield\n\n    del os.environ[\"SUNPY_CONFIGDIR\"]\n    astropy.config.paths.set_temp_config._temp_path = None\n    astropy.config.paths.set_temp_cache._temp_path = None\n\n\n@pytest.fixture()\ndef undo_config_dir_patch():\n    \"\"\"\n    Provide a way for certain tests to not have the config dir.\n    \"\"\"\n    oridir = os.environ[\"SUNPY_CONFIGDIR\"]\n    del os.environ[\"SUNPY_CONFIGDIR\"]\n    yield\n    os.environ[\"SUNPY_CONFIGDIR\"] = oridir\n\n\n@pytest.fixture(scope='session', autouse=True)\ndef tmp_dl_dir(request):\n    \"\"\"\n    Globally set the default download directory for the test run to a tmp dir.\n    \"\"\"\n    with tempfile.TemporaryDirectory() as tmpdir:\n        os.environ[\"SUNPY_DOWNLOADDIR\"] = tmpdir\n        yield tmpdir\n        del os.environ[\"SUNPY_DOWNLOADDIR\"]\n\n\n@pytest.fixture()\ndef undo_download_dir_patch():\n    \"\"\"\n    Provide a way for certain tests to not have tmp download dir.\n    \"\"\"\n    oridir = os.environ[\"SUNPY_DOWNLOADDIR\"]\n    del os.environ[\"SUNPY_DOWNLOADDIR\"]\n    yield\n    os.environ[\"SUNPY_DOWNLOADDIR\"] = oridir\n\n\ndef pytest_runtest_setup(item):\n    \"\"\"\n    pytest hook to skip all tests that have the mark 'remotedata' if the\n    pytest_remotedata plugin is not installed.\n    \"\"\"\n    if isinstance(item, pytest.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\n    # If at least one figure test has been run, print result image directory\n    if len(new_hash_library) > 0:\n        # Write the new hash library in JSON\n        figure_base_dir = pathlib.Path(config.getoption(\"--figure_dir\"))\n        hashfile = 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        \"\"\"\n        Turn on internet when generating the figure comparison webpage.\n        \"\"\"\n        if HAVE_REMOTEDATA:\n            from pytest_remotedata.disable_internet import turn_on_internet, turn_off_internet\n        else:\n            def turn_on_internet(): pass\n            def turn_off_internet(): pass\n\n        turn_on_internet()\n        generate_figure_webpage(new_hash_library)\n        turn_off_internet()\n\n        print('All images from image tests can be found in {}'.format(figure_base_dir.resolve()))\n        print(\"The corresponding hash library is {}\".format(hashfile.resolve()))\n\n\ndef pytest_sessionstart(session):\n    warnings.simplefilter(\"error\", SunpyDeprecationWarning)\n", "path": "sunpy/conftest.py"}], "after_files": [{"content": "import os\nimport json\nimport pathlib\nimport warnings\nimport importlib\nimport tempfile\n\nimport pytest\n\nimport astropy\nimport astropy.config.paths\n\nimport sunpy.tests.helpers\nfrom sunpy.tests.hash import HASH_LIBRARY_NAME\nfrom sunpy.tests.helpers import new_hash_library, generate_figure_webpage\nfrom sunpy.util.exceptions import SunpyDeprecationWarning\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\n# Don't actually import pytest_remotedata because that can do things to the\n# entrypoints code in pytest.\nremotedata_spec = importlib.util.find_spec(\"pytest_remotedata\")\nHAVE_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 = pathlib.Path(\n        request.config.getoption(\"--figure_dir\"))\n\n\n@pytest.fixture(scope='session', autouse=True)\ndef tmp_config_dir(request):\n    \"\"\"\n    Globally set the default config for all tests.\n    \"\"\"\n    tmpdir = tempfile.TemporaryDirectory()\n\n    os.environ[\"SUNPY_CONFIGDIR\"] = str(tmpdir.name)\n    astropy.config.paths.set_temp_config._temp_path = str(tmpdir.name)\n    astropy.config.paths.set_temp_cache._temp_path = str(tmpdir.name)\n\n    yield\n\n    del os.environ[\"SUNPY_CONFIGDIR\"]\n    astropy.config.paths.set_temp_config._temp_path = None\n    astropy.config.paths.set_temp_cache._temp_path = None\n\n\n@pytest.fixture()\ndef undo_config_dir_patch():\n    \"\"\"\n    Provide a way for certain tests to not have the config dir.\n    \"\"\"\n    oridir = os.environ[\"SUNPY_CONFIGDIR\"]\n    del os.environ[\"SUNPY_CONFIGDIR\"]\n    yield\n    os.environ[\"SUNPY_CONFIGDIR\"] = oridir\n\n\n@pytest.fixture(scope='session', autouse=True)\ndef tmp_dl_dir(request):\n    \"\"\"\n    Globally set the default download directory for the test run to a tmp dir.\n    \"\"\"\n    with tempfile.TemporaryDirectory() as tmpdir:\n        os.environ[\"SUNPY_DOWNLOADDIR\"] = tmpdir\n        yield tmpdir\n        del os.environ[\"SUNPY_DOWNLOADDIR\"]\n\n\n@pytest.fixture()\ndef undo_download_dir_patch():\n    \"\"\"\n    Provide a way for certain tests to not have tmp download dir.\n    \"\"\"\n    oridir = os.environ[\"SUNPY_DOWNLOADDIR\"]\n    del os.environ[\"SUNPY_DOWNLOADDIR\"]\n    yield\n    os.environ[\"SUNPY_DOWNLOADDIR\"] = oridir\n\n\ndef pytest_runtest_setup(item):\n    \"\"\"\n    pytest hook to skip all tests that have the mark 'remotedata' if the\n    pytest_remotedata plugin is not installed.\n    \"\"\"\n    if isinstance(item, pytest.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\n    # If at least one figure test has been run, print result image directory\n    if len(new_hash_library) > 0:\n        # Write the new hash library in JSON\n        figure_base_dir = pathlib.Path(config.getoption(\"--figure_dir\"))\n        hashfile = 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        \"\"\"\n        Turn on internet when generating the figure comparison webpage.\n        \"\"\"\n        if HAVE_REMOTEDATA:\n            from pytest_remotedata.disable_internet import turn_on_internet, turn_off_internet\n        else:\n            def turn_on_internet(): pass\n            def turn_off_internet(): pass\n\n        turn_on_internet()\n        generate_figure_webpage(new_hash_library)\n        turn_off_internet()\n\n        print('All images from image tests can be found in {}'.format(figure_base_dir.resolve()))\n        print(\"The corresponding hash library is {}\".format(hashfile.resolve()))\n\n\ndef pytest_sessionstart(session):\n    warnings.simplefilter(\"error\", SunpyDeprecationWarning)\n", "path": "sunpy/conftest.py"}]}