From 8dc33bd53dfd30117940a436b626311660a8e0c7 Mon Sep 17 00:00:00 2001
From: Alexandre Ghiti <alexandre.ghiti@canonical.com>
Date: Tue, 24 May 2022 10:54:00 +0200
Subject: [PATCH] Move tests files to tmp for user to have write access

---
 astroquery/esa/hubble/tests/test_esa_hubble.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

--- a/astroquery/esa/hubble/tests/test_esa_hubble.py
+++ b/astroquery/esa/hubble/tests/test_esa_hubble.py
@@ -24,6 +24,7 @@
 from unittest.mock import MagicMock
 from astropy.table.table import Table
 import shutil
+import tempfile
 
 
 def data_path(filename):
@@ -35,8 +36,10 @@
     file = 'm31.vot'
     if 'OBSERVATION_ID' in params:
         file = params['OBSERVATION_ID'] + ".vot"
-    response = data_path(file)
-    shutil.copy(response + '.test', response)
+    initial_response = data_path(file)
+    tmp_dir = tempfile.mkdtemp()
+    response = os.path.join(tmp_dir, file)
+    shutil.copy(initial_response + '.test', response)
     return response
 
 
@@ -54,8 +57,10 @@
     file = data_path('cone_search_m31_5.vot')
     if 'OBSERVATION_ID' in params:
         file = params['OBSERVATION_ID'] + ".vot"
-    response = data_path(file)
-    shutil.copy(response + '.test', response)
+    filename = os.path.basename(file)
+    tmp_dir = tempfile.mkdtemp()
+    response = os.path.join(tmp_dir, filename)
+    shutil.copy(file + '.test', response)
     return response
 
 
--- a/astroquery/cadc/tests/test_cadctap.py
+++ b/astroquery/cadc/tests/test_cadctap.py
@@ -373,7 +373,7 @@
     response = Mock()
     response.to_table.return_value = buffer.getvalue()
     cadc.cadctap.search = Mock(return_value=response)
-    output_file = '{}/test_vooutput.xml'.format(tempfile.tempdir)
+    output_file = '{}/test_vooutput.xml'.format(tempfile.mkdtemp())
     cadc.exec_sync('some query', output_file=output_file)
 
     actual = parse(output_file)
