From: Michael R. Crusoe <crusoe@debian.org>
Subject: tests: write no files to the current working directory
Forwarded: https://github.com/DataBiosphere/toil/pull/5684
--- toil.orig/src/toil/test/cwl/cwlTest.py
+++ toil/src/toil/test/cwl/cwlTest.py
@@ -238,14 +238,14 @@
     inputs.
     """
 
-    def test_cwl_cmdline_input(self) -> None:
+    def test_cwl_cmdline_input(self, tmp_path: Path) -> None:
         """
         Test that running a CWL workflow with inputs specified on the command line passes.
         """
         from toil.cwl import cwltoil
 
         with get_data("test/cwl/conditional_wf.cwl") as cwlfile:
-            args = [str(cwlfile), "--message", "str", "--sleep", "2"]
+            args = [f"--outdir={tmp_path}", str(cwlfile), "--message", "str", "--sleep", "2"]
             st = StringIO()
             # If the workflow runs, it must have had options
             cwltoil.main(args, stdout=st)
@@ -1925,6 +1925,7 @@
             f"--jobStore={tmp_path / 'jobstore'}",
             "--strict-memory-limit",
             f"--log-dir={log_dir}",
+            f"--outdir={tmp_path / 'results'}",
             str(cwl_file),
         ]
         p = subprocess.run(cmd, capture_output=True, text=True)
@@ -1968,7 +1969,8 @@
             "toil-cwl-runner",
             f"--jobStore={job_store}",
             "--strict-memory-limit",
-            f"--log-dir={str(log_dir)}",
+            f"--log-dir={log_dir}",
+            f"--outdir={tmp_path / 'results'}",
             str(cwl_file),
         ]
         subprocess.run(cmd)
@@ -1994,11 +1996,12 @@
     with get_data("test/cwl/echo-stderr.cwl") as cwl_file:
         cmd = [
             "toil-cwl-runner",
-            f"--jobStore={str(tmp_path / 'test_log_dir_echo_stderr')}",
+            f"--jobStore={tmp_path / 'test_log_dir_echo_stderr'}",
             "--strict-memory-limit",
             "--force-docker-pull",
             "--clean=always",
-            f"--log-dir={str(log_dir)}",
+            f"--log-dir={log_dir}",
+            f"--outdir={tmp_path / 'results'}",
             str(cwl_file),
         ]
         subprocess.run(cmd)
@@ -2219,6 +2222,7 @@
             "toil-cwl-runner",
             f"--jobStore=file:{tmp_path / 'jobStore'}",
             "--strict-memory-limit",
+            f"--outdir={tmp_path / 'results'}",
             str(cwl_file),
         ]
         p = subprocess.run(cmd, capture_output=True, text=True)
@@ -2253,6 +2257,7 @@
         cmd = [
             "toil-cwl-runner",
             f"--jobStore=file:{tmp_path / 'jobStore'}",
+            f"--outdir={tmp_path / 'results'}",
             str(cwl_file),
         ]
         p = subprocess.run(cmd, capture_output=True, text=True)
@@ -2682,7 +2687,7 @@
 @needs_cwl
 @pytest.mark.cwl
 @pytest.mark.timeout(300)
-def test_import_on_workers() -> None:
+def test_import_on_workers(tmp_path: Path) -> None:
     from toil.cwl import cwltoil
 
     detector = ImportWorkersMessageHandler()
@@ -2702,6 +2707,7 @@
                 "--logLevel=INFO",
                 "--logColors=False",
                 "--disableChaining=True",
+                f"--outdir={tmp_path}",
                 str(cwl_file),
                 "--input",
                 str(file_path),
--- toil.orig/src/toil/test/jobStores/jobStoreTest.py
+++ toil/src/toil/test/jobStores/jobStoreTest.py
@@ -118,7 +118,7 @@
 
         def setUp(self):
             super().setUp()
-            self.namePrefix = "jobstore-test-" + str(uuid.uuid4())
+            self.namePrefix = mkdtemp() + "jobstore-test-" + str(uuid.uuid4())
             self.config = self._createConfig()
 
             # Jobstores to be used in testing.
--- toil.orig/src/toil/test/options/options.py
+++ toil/src/toil/test/options/options.py
@@ -19,7 +19,7 @@
         """
         parser = ArgParser()
         addOptions(parser, jobstore_as_flag=True, wdl=False, cwl=False)
-        test_args = ["--jobstore=example-jobstore", "--batchSystem=slurm"]
+        test_args = [f"--jobstore={self._getTestJobStorePath()}", "--batchSystem=slurm"]
         options = parser.parse_args(test_args)
         with Toil(options) as toil:
             caching_value = toil.config.caching
@@ -41,7 +41,7 @@
         # the kubernetes batchsystem (and I think all batchsystems including singlemachine) return False
         # for default_caching
         test_args = [
-            "--jobstore=example-jobstore",
+            f"--jobstore={self._getTestJobStorePath()}",
             "--batchSystem=kubernetes",
             "--caching=True",
         ]
--- toil.orig/src/toil/test/sort/restart_sort.py
+++ toil/src/toil/test/sort/restart_sort.py
@@ -26,6 +26,7 @@
 from toil.common import Toil
 from toil.job import Job
 from toil.realtimeLogger import RealtimeLogger
+from toil.lib.io import mkdtemp
 
 defaultLines = 1000
 defaultLineLen = 50
@@ -284,7 +285,7 @@
     fileName = options.fileToSort
     if options.fileToSort is None:
         # make the file ourselves
-        fileName = "fileToSort.txt"
+        fileName = os.path.join(mkdtemp(), "fileToSort.txt")
         if os.path.exists(fileName):
             print(f"Sorting existing file: {fileName}")
         else:
--- toil.orig/src/toil/test/sort/sort.py
+++ toil/src/toil/test/sort/sort.py
@@ -22,6 +22,7 @@
 
 from toil.common import Toil
 from toil.job import Job
+from toil.lib.io import mkdtemp
 from toil.lib.misc import StrPath
 from toil.realtimeLogger import RealtimeLogger
 
@@ -284,7 +285,7 @@
     fileName = options.fileToSort
     if options.fileToSort is None:
         # make the file ourselves
-        fileName = "fileToSort.txt"
+        fileName = os.path.join(mkdtemp(), "fileToSort.txt")
         if os.path.exists(fileName):
             print(f"Sorting existing file: {fileName}")
         else:
--- toil.orig/src/toil/utils/toilDebugFile.py
+++ toil/src/toil/utils/toilDebugFile.py
@@ -20,6 +20,7 @@
 from toil.common import Config, Toil, parser_with_common_options
 from toil.jobStores.fileJobStore import FileJobStore
 from toil.lib.conversions import strtobool
+from toil.lib.io import mkdtemp
 from toil.lib.resources import glob
 from toil.statsAndLogging import set_logging_from_options
 
@@ -60,7 +61,7 @@
     Fetch a list of all files contained in the job store if nameOfJob is not
     declared, otherwise it only prints out the names of files for that specific
     job for which it can find a match.  Also creates a log file of these file
-    names in the current directory.
+    names in a temporary directory.
 
     :param job_store: Job store to ask for files from.
     :param job_id: Default is None, which prints out all files in the jobStore.
@@ -72,18 +73,18 @@
     # FileJobStore.
 
     if job_id:
-        logFile = job_id.replace("/", "_") + "_fileset.txt"
+        logFile = os.path.join(mkdtemp(), job_id.replace("/", "_") + "_fileset.txt")
     else:
-        logFile = "jobstore_files.txt"
+        logFile = os.path.join(mkdtemp(), "jobstore_files.txt")
 
     list_of_files = job_store.list_all_file_names(for_job=job_id)
     if os.path.exists(logFile):
         os.remove(logFile)
     for gfile in sorted(list_of_files):
         if job_id:
-            logger.debug(f"{job_id} File: {os.path.basename(gfile)}")
+            logger.debug(f"{job_id} File: {os.path.basename(gfile)}, log: {logFile}")
         else:
-            logger.debug(f"File: {os.path.basename(gfile)}")
+            logger.debug(f"File: {os.path.basename(gfile)}, log: {logFile}")
         with open(logFile, "a+") as f:
             f.write(os.path.basename(gfile))
             f.write("\n")
--- toil.orig/src/toil/test/batchSystems/batch_system_plugin_test.py
+++ toil/src/toil/test/batchSystems/batch_system_plugin_test.py
@@ -87,7 +87,7 @@
         parser = ArgParser()
         addOptions(parser)
 
-        options = parser.parse_args(["test-jobstore", "--clean=always"])
+        options = parser.parse_args(["--clean=always", self._getTestJobStorePath()])
 
         # try to install a batchsystem plugin with some arguments
         # if the arguments exists, the values should also exist in the config
--- toil.orig/src/toil/test/utils/utilsTest.py
+++ toil/src/toil/test/utils/utilsTest.py
@@ -632,6 +632,7 @@
             python,
             "-m",
             "toil.test.sort.sort",
+            f"--outputFile={tmp_path/'sortedFile.txt'}",
             "--logDebug",
             jobstore.as_uri(),
             "--restart",
