diff --git a/phasecalculator/test/runnerstest/fgipanalysisrunnertest.py b/phasecalculator/test/runnerstest/fgipanalysisrunnertest.py
index 7175507d1d28b976f3cfe08bca226030e998011f..d052e1c681875f0d7576985e52aea9f452caec21 100755
--- a/phasecalculator/test/runnerstest/fgipanalysisrunnertest.py
+++ b/phasecalculator/test/runnerstest/fgipanalysisrunnertest.py
@@ -25,6 +25,7 @@ import logging
 import unittest
 import pathlib
 import os
+import shutil
 from testfixtures import Replacer
 from testfixtures.popen import MockPopen
 import phasecalculator.runners.fgipanalysisrunner as fgiprunner
@@ -78,18 +79,15 @@ class FGIPAnalysisRunnerTestCase(unittest.TestCase):
         None.
 
         """
-        if pathlib.Path(self.matrix_file).exists():
-            os.remove(self.matrix_file)
-        if pathlib.Path(self.solvent_map).exists():
-            os.remove(self.solvent_map)
-        if pathlib.Path(self.fgip_file).is_file():
-            os.remove(self.fgip_file)
-        if pathlib.Path(self.poly_file).is_file():
-            os.remove(self.poly_file)
-        if pathlib.Path(self.energy_xmlfile).is_file():
-            os.remove(self.energy_xmlfile)
-        if pathlib.Path(self.directory).is_dir():
-            os.rmdir(self.directory)
+        for filename in os.listdir(self.directory_base):
+            file_path = os.path.join(self.directory_base, filename)
+            try:
+                if os.path.isfile(file_path) or os.path.islink(file_path):
+                    os.unlink(file_path)
+                elif os.path.isdir(file_path):
+                    shutil.rmtree(file_path)
+            except Exception as e:
+                LOGGER.error('Failed to delete %s. Reason: %s', file_path, e)
         if pathlib.Path(self.directory_base).is_dir():
             os.rmdir(self.directory_base)
     def test_calc_energies_and_fgips(self):