From: "Michael R. Crusoe" <crusoe@debian.org>
Date: Mon, 7 Jan 2019 05:08:12 -0800
Subject: Make tests more independent

Forwarded: https://github.com/DataBiosphere/toil/pull/5211
Last-Update: 2025-03-17
---
 MANIFEST.in                                        |   9 ++
 setup.py                                           |   4 +-
 src/toil/test/__init__.py                          |  19 ++++
 src/toil/test/cwl/cwlTest.py                       | 113 ++++++++++-----------
 src/toil/test/docs/scripts/tutorial_staging.py     |  10 +-
 .../test/provisioners/aws/awsProvisionerTest.py    |   5 +-
 src/toil/test/provisioners/clusterTest.py          |   2 +-
 src/toil/test/provisioners/gceProvisionerTest.py   |   9 +-
 src/toil/test/src/resourceTest.py                  |   2 -
 .../test/utils/ABCWorkflowDebug/debugWorkflow.py   |  10 +-
 src/toil/test/utils/toilDebugTest.py               |  14 ++-
 src/toil/test/utils/toilKillTest.py                |  10 +-
 src/toil/test/utils/utilsTest.py                   |  11 +-
 src/toil/test/wdl/wdltoil_test.py                  |  31 +++---
 14 files changed, 134 insertions(+), 115 deletions(-)

diff --git a/MANIFEST.in b/MANIFEST.in
index a4a46ee..35b3a05 100644
--- a/MANIFEST.in
+++ b/MANIFEST.in
@@ -1 +1,10 @@
 include requirements*.txt
+include src/toil/server/api_spec/workflow_execution_service.swagger.yaml
+include src/toil/test/cwl/colon_test_output_job.yaml
+include src/toil/test/cwl/conditional_wf.yaml
+include src/toil/test/cwl/mock_mpi/fake_mpi.yml
+include src/toil/test/docs/scripts/*
+include src/toil/test/utils/ABCWorkflowDebug/sleep.yaml
+include src/toil/test/utils/ABCWorkflowDebug/*
+recursive-include src/toil/test/ *.cwl
+recursive-include src/toil/test/ *.txt
diff --git a/setup.py b/setup.py
index b5e0288..ad0f716 100755
--- a/setup.py
+++ b/setup.py
@@ -111,9 +111,7 @@ def run_setup():
         extras_require=extras_require,
         package_dir={"": "src"},
         packages=find_packages(where="src"),
-        package_data={
-            "": ["*.yml", "*.yaml", "cloud-config", "*.cwl"],
-        },
+        include_package_data=True,
         # Unfortunately, the names of the entry points are hard-coded elsewhere in the code base so
         # you can't just change them here. Luckily, most of them are pretty unique strings, and thus
         # easy to search for.
diff --git a/src/toil/test/__init__.py b/src/toil/test/__init__.py
index 1ebaf74..c9198a2 100644
--- a/src/toil/test/__init__.py
+++ b/src/toil/test/__init__.py
@@ -30,6 +30,7 @@ from abc import ABCMeta, abstractmethod
 from collections.abc import Generator
 from contextlib import contextmanager
 from inspect import getsource
+from pathlib import Path
 from shutil import which
 from tempfile import mkstemp
 from textwrap import dedent
@@ -38,6 +39,8 @@ from unittest.util import strclass
 from urllib.error import HTTPError, URLError
 from urllib.request import urlopen
 
+from pkg_resources import Requirement, ResolutionError, resource_filename
+
 from toil import ApplianceImageNotFound, applianceSelf, toilPackageDirPath
 from toil.lib.accelerators import (
     have_working_nvidia_docker_runtime,
@@ -52,6 +55,22 @@ from toil.version import distVersion
 logger = logging.getLogger(__name__)
 
 
+def get_data(filename: str) -> str:
+    """Returns an absolute path for a file from this package."""
+    # normalizing path depending on OS or else it will cause problem when joining path
+    filename = os.path.normpath(filename)
+    filepath = None
+    try:
+        filepath = resource_filename(Requirement.parse("toil"), filename)
+    except ResolutionError:
+        pass
+    if not filepath or not os.path.isfile(filepath):
+        filepath = os.path.join(
+            os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, filename
+        )
+    return str(Path(filepath).resolve())
+
+
 class ToilTest(unittest.TestCase):
     """
     A common base class for Toil tests.
diff --git a/src/toil/test/cwl/cwlTest.py b/src/toil/test/cwl/cwlTest.py
index 4098976..822cfb4 100644
--- a/src/toil/test/cwl/cwlTest.py
+++ b/src/toil/test/cwl/cwlTest.py
@@ -51,6 +51,7 @@ from toil.fileStores.abstractFileStore import AbstractFileStore
 from toil.lib.threading import cpu_count
 from toil.test import (
     ToilTest,
+    get_data,
     needs_aws_s3,
     needs_cwl,
     needs_docker,
@@ -237,7 +238,6 @@ class CWLWorkflowTest(ToilTest):
         """Runs anew before each test to create farm fresh temp dirs."""
         self.outDir = f"/tmp/toil-cwl-test-{str(uuid.uuid4())}"
         os.makedirs(self.outDir)
-        self.rootDir = self._projectRootPath()
         self.jobStoreDir = f"./jobstore-{str(uuid.uuid4())}"
 
     def tearDown(self) -> None:
@@ -254,7 +254,7 @@ class CWLWorkflowTest(ToilTest):
         """
         from toil.cwl import cwltoil
 
-        cwlfile = "src/toil/test/cwl/conditional_wf.cwl"
+        cwlfile = get_data("toil/test/cwl/conditional_wf.cwl")
         args = [cwlfile, "--message", "str", "--sleep", "2"]
         st = StringIO()
         # If the workflow runs, it must have had options
@@ -278,8 +278,8 @@ class CWLWorkflowTest(ToilTest):
             main_args.extend(["--logDebug", "--outdir", self.outDir])
         main_args.extend(
             [
-                os.path.join(self.rootDir, cwlfile),
-                os.path.join(self.rootDir, jobfile),
+                cwlfile,
+                jobfile,
             ]
         )
         cwltoil.main(main_args, stdout=st)
@@ -312,8 +312,8 @@ class CWLWorkflowTest(ToilTest):
                 "--debugWorker",
                 "--outdir",
                 self.outDir,
-                os.path.join(self.rootDir, cwlfile),
-                os.path.join(self.rootDir, jobfile),
+                cwlfile,
+                jobfile,
             ],
             stdout=st,
         )
@@ -325,46 +325,46 @@ class CWLWorkflowTest(ToilTest):
 
     def revsort(self, cwl_filename: str, tester_fn: TesterFuncType) -> None:
         tester_fn(
-            "src/toil/test/cwl/" + cwl_filename,
-            "src/toil/test/cwl/revsort-job.json",
+            get_data(f"toil/test/cwl/{cwl_filename}"),
+            get_data("toil/test/cwl/revsort-job.json"),
             self._expected_revsort_output(self.outDir),
         )
 
     def revsort_no_checksum(self, cwl_filename: str, tester_fn: TesterFuncType) -> None:
         tester_fn(
-            "src/toil/test/cwl/" + cwl_filename,
-            "src/toil/test/cwl/revsort-job.json",
+            get_data(f"toil/test/cwl/{cwl_filename}"),
+            get_data("toil/test/cwl/revsort-job.json"),
             self._expected_revsort_nochecksum_output(self.outDir),
         )
 
     def download(self, inputs: str, tester_fn: TesterFuncType) -> None:
-        input_location = os.path.join("src/toil/test/cwl", inputs)
+        input_location = get_data(f"toil/test/cwl/{inputs}")
         tester_fn(
-            "src/toil/test/cwl/download.cwl",
+            get_data("toil/test/cwl/download.cwl"),
             input_location,
             self._expected_download_output(self.outDir),
         )
 
     def load_contents(self, inputs: str, tester_fn: TesterFuncType) -> None:
-        input_location = os.path.join("src/toil/test/cwl", inputs)
+        input_location = get_data(f"toil/test/cwl/{inputs}")
         tester_fn(
-            "src/toil/test/cwl/load_contents.cwl",
+            get_data("toil/test/cwl/load_contents.cwl"),
             input_location,
             self._expected_load_contents_output(self.outDir),
         )
 
     def download_directory(self, inputs: str, tester_fn: TesterFuncType) -> None:
-        input_location = os.path.join("src/toil/test/cwl", inputs)
+        input_location = get_data(f"toil/test/cwl/{inputs}")
         tester_fn(
-            "src/toil/test/cwl/download_directory.cwl",
+            get_data("toil/test/cwl/download_directory.cwl"),
             input_location,
             self._expected_download_output(self.outDir),
         )
 
     def download_subdirectory(self, inputs: str, tester_fn: TesterFuncType) -> None:
-        input_location = os.path.join("src/toil/test/cwl", inputs)
+        input_location = get_data(f"toil/test/cwl/{inputs}")
         tester_fn(
-            "src/toil/test/cwl/download_subdirectory.cwl",
+            get_data("toil/test/cwl/download_subdirectory.cwl"),
             input_location,
             self._expected_download_output(self.outDir),
         )
@@ -379,11 +379,11 @@ class CWLWorkflowTest(ToilTest):
             "--enable-dev",
             "--enable-ext",
             "--mpi-config-file",
-            os.path.join(self.rootDir, "src/toil/test/cwl/mock_mpi/fake_mpi.yml"),
-            os.path.join(self.rootDir, "src/toil/test/cwl/mpi_simple.cwl"),
+            get_data("toil/test/cwl/mock_mpi/fake_mpi.yml"),
+            get_data("toil/test/cwl/mpi_simple.cwl"),
         ]
         path = os.environ["PATH"]
-        os.environ["PATH"] = f"{path}:{self.rootDir}/src/toil/test/cwl/mock_mpi/"
+        os.environ["PATH"] = f"{path}:{get_data('toil/test/cwl/mock_mpi/')}"
         cwltoil.main(main_args, stdout=stdout)
         os.environ["PATH"] = path
         out = json.loads(stdout.getvalue())
@@ -401,8 +401,8 @@ class CWLWorkflowTest(ToilTest):
         main_args = [
             "--outdir",
             self.outDir,
-            os.path.join(self.rootDir, "src/toil/test/cwl/s3_secondary_file.cwl"),
-            os.path.join(self.rootDir, "src/toil/test/cwl/s3_secondary_file.json"),
+            get_data("toil/test/cwl/s3_secondary_file.cwl"),
+            get_data("toil/test/cwl/s3_secondary_file.json"),
         ]
         cwltoil.main(main_args, stdout=stdout)
         out = json.loads(stdout.getvalue())
@@ -434,8 +434,8 @@ class CWLWorkflowTest(ToilTest):
 
     def test_run_colon_output(self) -> None:
         self._tester(
-            "src/toil/test/cwl/colon_test_output.cwl",
-            "src/toil/test/cwl/colon_test_output_job.yaml",
+            get_data("toil/test/cwl/colon_test_output.cwl"),
+            get_data("toil/test/cwl/colon_test_output_job.yaml"),
             self._expected_colon_output(self.outDir),
             out_name="result",
         )
@@ -464,8 +464,8 @@ class CWLWorkflowTest(ToilTest):
             # We need to output to the current directory to make sure that
             # works.
             self._tester(
-                "src/toil/test/cwl/glob_dir.cwl",
-                "src/toil/test/cwl/empty.json",
+                get_data("toil/test/cwl/glob_dir.cwl"),
+                get_data("toil/test/cwl/empty.json"),
                 self._expected_glob_dir_output(os.getcwd()),
                 main_args=["--bypass-file-store"],
                 output_here=True,
@@ -480,8 +480,8 @@ class CWLWorkflowTest(ToilTest):
     def test_required_input_condition_protection(self) -> None:
         # This doesn't run containerized
         self._tester(
-            "src/toil/test/cwl/not_run_required_input.cwl",
-            "src/toil/test/cwl/empty.json",
+            get_data("toil/test/cwl/not_run_required_input.cwl"),
+            get_data("toil/test/cwl/empty.json"),
             {},
         )
 
@@ -506,7 +506,7 @@ class CWLWorkflowTest(ToilTest):
             "--slurmDefaultAllMem=True",
             "--outdir",
             self.outDir,
-            os.path.join(self.rootDir, "src/toil/test/cwl/measure_default_memory.cwl"),
+            get_data("toil/test/cwl/measure_default_memory.cwl"),
         ]
         try:
             log.debug("Start test workflow")
@@ -600,8 +600,8 @@ class CWLWorkflowTest(ToilTest):
     @unittest.skip("Fails too often due to remote service")
     def test_bioconda(self) -> None:
         self._tester(
-            "src/toil/test/cwl/seqtk_seq.cwl",
-            "src/toil/test/cwl/seqtk_seq_job.json",
+            get_data("toil/test/cwl/seqtk_seq.cwl"),
+            get_data("toil/test/cwl/seqtk_seq_job.json"),
             self._expected_seqtk_output(self.outDir),
             main_args=["--beta-conda-dependencies"],
             out_name="output1",
@@ -610,8 +610,8 @@ class CWLWorkflowTest(ToilTest):
     @needs_docker
     def test_default_args(self) -> None:
         self._tester(
-            "src/toil/test/cwl/seqtk_seq.cwl",
-            "src/toil/test/cwl/seqtk_seq_job.json",
+            get_data("toil/test/cwl/seqtk_seq.cwl"),
+            get_data("toil/test/cwl/seqtk_seq_job.json"),
             self._expected_seqtk_output(self.outDir),
             main_args=[
                 "--default-container",
@@ -625,8 +625,8 @@ class CWLWorkflowTest(ToilTest):
     @unittest.skip("Fails too often due to remote service")
     def test_biocontainers(self) -> None:
         self._tester(
-            "src/toil/test/cwl/seqtk_seq.cwl",
-            "src/toil/test/cwl/seqtk_seq_job.json",
+            get_data("toil/test/cwl/seqtk_seq.cwl"),
+            get_data("toil/test/cwl/seqtk_seq_job.json"),
             self._expected_seqtk_output(self.outDir),
             main_args=["--beta-use-biocontainers"],
             out_name="output1",
@@ -637,8 +637,8 @@ class CWLWorkflowTest(ToilTest):
     @needs_local_cuda
     def test_cuda(self) -> None:
         self._tester(
-            "src/toil/test/cwl/nvidia_smi.cwl",
-            "src/toil/test/cwl/empty.json",
+            get_data("toil/test/cwl/nvidia_smi.cwl"),
+            get_data("toil/test/cwl/empty.json"),
             {},
             out_name="result",
         )
@@ -709,8 +709,8 @@ class CWLWorkflowTest(ToilTest):
         Test that a file with 'streamable'=True is a named pipe.
         This is a CWL1.2 feature.
         """
-        cwlfile = "src/toil/test/cwl/stream.cwl"
-        jobfile = "src/toil/test/cwl/stream.json"
+        cwlfile = get_data("toil/test/cwl/stream.cwl")
+        jobfile = get_data("toil/test/cwl/stream.json")
         out_name = "output"
         jobstore = f"--jobStore=aws:us-west-1:toil-stream-{uuid.uuid4()}"
         from toil.cwl import cwltoil
@@ -721,8 +721,8 @@ class CWLWorkflowTest(ToilTest):
             "--outdir",
             self.outDir,
             jobstore,
-            os.path.join(self.rootDir, cwlfile),
-            os.path.join(self.rootDir, jobfile),
+            cwlfile,
+            jobfile,
         ]
         if extra_args:
             args = extra_args + args
@@ -747,8 +747,8 @@ class CWLWorkflowTest(ToilTest):
         """
         Tests that the http://arvados.org/cwl#UsePreemptible extension is supported.
         """
-        cwlfile = "src/toil/test/cwl/preemptible.cwl"
-        jobfile = "src/toil/test/cwl/empty.json"
+        cwlfile = get_data("toil/test/cwl/preemptible.cwl")
+        jobfile = get_data("toil/test/cwl/empty.json")
         out_name = "output"
         from toil.cwl import cwltoil
 
@@ -756,8 +756,8 @@ class CWLWorkflowTest(ToilTest):
         args = [
             "--outdir",
             self.outDir,
-            os.path.join(self.rootDir, cwlfile),
-            os.path.join(self.rootDir, jobfile),
+            cwlfile,
+            jobfile,
         ]
         cwltoil.main(args, stdout=st)
         out = json.loads(st.getvalue())
@@ -771,16 +771,16 @@ class CWLWorkflowTest(ToilTest):
         """
         Tests that the http://arvados.org/cwl#UsePreemptible extension is validated.
         """
-        cwlfile = "src/toil/test/cwl/preemptible_expression.cwl"
-        jobfile = "src/toil/test/cwl/preemptible_expression.json"
+        cwlfile = get_data("toil/test/cwl/preemptible_expression.cwl")
+        jobfile = get_data("toil/test/cwl/preemptible_expression.json")
         from toil.cwl import cwltoil
 
         st = StringIO()
         args = [
             "--outdir",
             self.outDir,
-            os.path.join(self.rootDir, cwlfile),
-            os.path.join(self.rootDir, jobfile),
+            cwlfile,
+            jobfile,
         ]
         try:
             cwltoil.main(args, stdout=st)
@@ -938,8 +938,7 @@ class CWLv10Test(ToilTest):
         """Runs anew before each test to create farm fresh temp dirs."""
         self.outDir = f"/tmp/toil-cwl-test-{str(uuid.uuid4())}"
         os.makedirs(self.outDir)
-        self.rootDir = self._projectRootPath()
-        self.cwlSpec = os.path.join(self.rootDir, "src/toil/test/cwl/spec")
+        self.cwlSpec = get_data("toil/test/cwl/spec")
         self.workDir = os.path.join(self.cwlSpec, "v1.0")
         # The latest cwl git commit hash from https://github.com/common-workflow-language/common-workflow-language.
         # Update it to get the latest tests.
@@ -1072,15 +1071,13 @@ class CWLv11Test(ToilTest):
     Run the CWL 1.1 conformance tests in various environments.
     """
 
-    rootDir: str
     cwlSpec: str
     test_yaml: str
 
     @classmethod
     def setUpClass(cls) -> None:
         """Runs anew before each test."""
-        cls.rootDir = cls._projectRootPath()
-        cls.cwlSpec = os.path.join(cls.rootDir, "src/toil/test/cwl/spec_v11")
+        cls.cwlSpec = get_data("toil/test/cwl/spec_v11")
         cls.test_yaml = os.path.join(cls.cwlSpec, "conformance_tests.yaml")
         # TODO: Use a commit zip in case someone decides to rewrite master's history?
         url = "https://github.com/common-workflow-language/cwl-v1.1.git"
@@ -1152,7 +1149,7 @@ class CWLv12Test(ToilTest):
     def setUpClass(cls) -> None:
         """Runs anew before each test."""
         cls.rootDir = cls._projectRootPath()
-        cls.cwlSpec = os.path.join(cls.rootDir, "src/toil/test/cwl/spec_v12")
+        cls.cwlSpec = get_data("toil/test/cwl/spec_v12")
         cls.test_yaml = os.path.join(cls.cwlSpec, "conformance_tests.yaml")
         # TODO: Use a commit zip in case someone decides to rewrite master's history?
         url = "https://github.com/common-workflow-language/cwl-v1.2.git"
@@ -1770,8 +1767,8 @@ def test_download_structure(tmp_path: Path) -> None:
 @pytest.mark.timeout(300)
 def test_import_on_workers() -> None:
     args = [
-        "src/toil/test/cwl/download.cwl",
-        "src/toil/test/cwl/download_file.json",
+        get_data("toil/test/cwl/download.cwl"),
+        get_data("toil/test/cwl/download_file.json"),
         "--runImportsOnWorkers",
         "--importWorkersDisk=10MiB",
         "--realTimeLogging=True",
diff --git a/src/toil/test/docs/scripts/tutorial_staging.py b/src/toil/test/docs/scripts/tutorial_staging.py
index 17c2782..c2099ad 100644
--- a/src/toil/test/docs/scripts/tutorial_staging.py
+++ b/src/toil/test/docs/scripts/tutorial_staging.py
@@ -3,7 +3,7 @@ import os
 from toil.common import Toil
 from toil.job import Job
 from toil.lib.io import mkdtemp
-
+from toil.test import get_data
 
 class HelloWorld(Job):
     def __init__(self, id):
@@ -22,6 +22,7 @@ class HelloWorld(Job):
 
 if __name__ == "__main__":
     jobstore: str = mkdtemp("tutorial_staging")
+    tmp: str = mkdtemp("tutorial_staging_tmp")
     os.rmdir(jobstore)
     options = Job.Runner.getDefaultOptions(jobstore)
     options.logLevel = "INFO"
@@ -29,11 +30,8 @@ if __name__ == "__main__":
 
     with Toil(options) as toil:
         if not toil.options.restart:
-            ioFileDirectory = os.path.join(
-                os.path.dirname(os.path.abspath(__file__)), "stagingExampleFiles"
-            )
             inputFileID = toil.importFile(
-                "file://" + os.path.abspath(os.path.join(ioFileDirectory, "in.txt"))
+                "file://" + get_data("toil/test/docs/scripts/stagingExampleFiles/in.txt")
             )
             outputFileID = toil.start(HelloWorld(inputFileID))
         else:
@@ -41,5 +39,5 @@ if __name__ == "__main__":
 
         toil.exportFile(
             outputFileID,
-            "file://" + os.path.abspath(os.path.join(ioFileDirectory, "out.txt")),
+            "file://" + os.path.join(tmp + "out.txt"),
         )
diff --git a/src/toil/test/provisioners/aws/awsProvisionerTest.py b/src/toil/test/provisioners/aws/awsProvisionerTest.py
index cae25e4..a505da4 100644
--- a/src/toil/test/provisioners/aws/awsProvisionerTest.py
+++ b/src/toil/test/provisioners/aws/awsProvisionerTest.py
@@ -28,6 +28,7 @@ from toil.provisioners import cluster_factory
 from toil.provisioners.aws.awsProvisioner import AWSProvisioner
 from toil.test import (
     ToilTest,
+    get_data,
     integrative,
     needs_aws_ec2,
     needs_fetchable_appliance,
@@ -286,7 +287,7 @@ class AWSAutoscaleTest(AbstractAWSAutoscaleTest):
             # Fixme: making this file larger causes the test to hang
             f.write("01234567890123456789012345678901")
         self.rsyncUtil(
-            os.path.join(self._projectRootPath(), "src/toil/test/sort/sort.py"),
+            get_data("toil/test/sort/sort.py"),
             ":" + self.script(),
         )
         self.rsyncUtil(fileToSort, ":" + self.data("sortFile"))
@@ -502,7 +503,7 @@ class AWSAutoscaleTestMultipleNodeTypes(AbstractAWSAutoscaleTest):
         with open(sseKeyFile, "w") as f:
             f.write("01234567890123456789012345678901")
         self.rsyncUtil(
-            os.path.join(self._projectRootPath(), "src/toil/test/sort/sort.py"),
+            get_data("toil/test/sort/sort.py"),
             ":" + self.script(),
         )
         self.rsyncUtil(sseKeyFile, ":" + self.data("keyFile"))
diff --git a/src/toil/test/provisioners/clusterTest.py b/src/toil/test/provisioners/clusterTest.py
index d642831..273c27a 100644
--- a/src/toil/test/provisioners/clusterTest.py
+++ b/src/toil/test/provisioners/clusterTest.py
@@ -39,7 +39,7 @@ log = logging.getLogger(__name__)
 class AbstractClusterTest(ToilTest):
     def __init__(self, methodName: str) -> None:
         super().__init__(methodName=methodName)
-        self.keyName = os.getenv("TOIL_AWS_KEYNAME").strip() or "id_rsa"
+        self.keyName = os.getenv("TOIL_AWS_KEYNAME", "id_rsa").strip()
         self.clusterName = f"aws-provisioner-test-{uuid4()}"
         self.leaderNodeType = "t2.medium"
         self.clusterType = "mesos"
diff --git a/src/toil/test/provisioners/gceProvisionerTest.py b/src/toil/test/provisioners/gceProvisionerTest.py
index a2852e0..56ad79a 100644
--- a/src/toil/test/provisioners/gceProvisionerTest.py
+++ b/src/toil/test/provisioners/gceProvisionerTest.py
@@ -21,6 +21,7 @@ import pytest
 
 from toil.test import (
     ToilTest,
+    get_data,
     integrative,
     needs_fetchable_appliance,
     needs_google_project,
@@ -215,7 +216,7 @@ class GCEAutoscaleTest(AbstractGCEAutoscaleTest):
             # Fixme: making this file larger causes the test to hang
             f.write("01234567890123456789012345678901")
         self.rsyncUtil(
-            os.path.join(self._projectRootPath(), "src/toil/test/sort/sort.py"),
+            get_data("toil/test/sort/sort.py"),
             ":/home/sort.py",
         )
         self.rsyncUtil(fileToSort, ":/home/sortFile")
@@ -325,7 +326,7 @@ class GCEAutoscaleTestMultipleNodeTypes(AbstractGCEAutoscaleTest):
         with open(sseKeyFile, "w") as f:
             f.write("01234567890123456789012345678901")
         self.rsyncUtil(
-            os.path.join(self._projectRootPath(), "src/toil/test/sort/sort.py"),
+            get_data("toil/test/sort/sort.py"),
             ":/home/sort.py",
         )
         self.rsyncUtil(sseKeyFile, ":/home/keyFile")
@@ -377,9 +378,7 @@ class GCERestartTest(AbstractGCEAutoscaleTest):
 
     def _getScript(self):
         self.rsyncUtil(
-            os.path.join(
-                self._projectRootPath(), "src/toil/test/provisioners/restartScript.py"
-            ),
+            get_data("toil/test/provisioners/restartScript.py"),
             ":" + self.scriptName,
         )
 
diff --git a/src/toil/test/src/resourceTest.py b/src/toil/test/src/resourceTest.py
index d2cc555..a7ab8ca 100644
--- a/src/toil/test/src/resourceTest.py
+++ b/src/toil/test/src/resourceTest.py
@@ -150,8 +150,6 @@ class ResourceTest(ToilTest):
         # Assert basic attributes and properties
         self.assertEqual(module.belongsToToil, shouldBelongToToil)
         self.assertEqual(module.name, module_name)
-        if shouldBelongToToil:
-            self.assertTrue(module.dirPath.endswith("/src"))
 
         # Before the module is saved as a resource, localize() and globalize() are identity
         # methods. This should log.warnings.
diff --git a/src/toil/test/utils/ABCWorkflowDebug/debugWorkflow.py b/src/toil/test/utils/ABCWorkflowDebug/debugWorkflow.py
index e32f59a..9d35008 100644
--- a/src/toil/test/utils/ABCWorkflowDebug/debugWorkflow.py
+++ b/src/toil/test/utils/ABCWorkflowDebug/debugWorkflow.py
@@ -6,6 +6,7 @@ import sys
 from toil.common import Toil
 from toil.job import Job
 from toil.lib.io import mkdtemp
+from toil.test import get_data
 from toil.version import python
 
 logger = logging.getLogger(__name__)
@@ -157,6 +158,7 @@ def broken_job(job, num):
 
 if __name__ == "__main__":
     jobStorePath = sys.argv[1] if len(sys.argv) > 1 else mkdtemp("debugWorkflow")
+    tmp: str = mkdtemp("debugWorkflow_tmp")
     options = Job.Runner.getDefaultOptions(jobStorePath)
     options.clean = "never"
     options.stats = True
@@ -164,20 +166,18 @@ if __name__ == "__main__":
     with Toil(options) as toil:
 
         B_file0 = toil.importFile(
-            "file://"
-            + os.path.abspath("src/toil/test/utils/ABCWorkflowDebug/B_file.txt")
+            f"file://{get_data('toil/test/utils/ABCWorkflowDebug/B_file.txt')}"
         )
         B_file0_preserveThisFilename = "B_file.txt"
         B_file = (B_file0, B_file0_preserveThisFilename)
 
         file_maker0 = toil.importFile(
-            "file://"
-            + os.path.abspath("src/toil/test/utils/ABCWorkflowDebug/mkFile.py")
+            f"file://{get_data('toil/test/utils/ABCWorkflowDebug/mkFile.py')}"
         )
         file_maker0_preserveThisFilename = "mkFile.py"
         file_maker = (file_maker0, file_maker0_preserveThisFilename)
 
-        filepath = os.path.abspath("src/toil/test/utils/ABCWorkflowDebug/ABC.txt")
+        filepath = os.path.join(tmp, "ABC.txt")
 
         job0 = Job.wrapJobFn(initialize_jobs)
         job1 = Job.wrapJobFn(writeA, file_maker)
diff --git a/src/toil/test/utils/toilDebugTest.py b/src/toil/test/utils/toilDebugTest.py
index 010cff6..aa8d773 100644
--- a/src/toil/test/utils/toilDebugTest.py
+++ b/src/toil/test/utils/toilDebugTest.py
@@ -17,7 +17,7 @@ import subprocess
 import tempfile
 
 from toil.lib.resources import glob
-from toil.test import ToilTest, needs_wdl, slow
+from toil.test import ToilTest, get_data, needs_wdl, slow
 from toil.version import python
 
 logger = logging.getLogger(__name__)
@@ -28,7 +28,7 @@ def workflow_debug_jobstore() -> str:
     subprocess.check_call(
         [
             python,
-            os.path.abspath("src/toil/test/utils/ABCWorkflowDebug/debugWorkflow.py"),
+            get_data("toil/test/utils/ABCWorkflowDebug/debugWorkflow.py"),
             job_store_path,
         ]
     )
@@ -49,7 +49,7 @@ def testJobStoreContents():
     subprocess.check_call(
         [
             python,
-            os.path.abspath("src/toil/utils/toilDebugFile.py"),
+            get_data("toil/utils/toilDebugFile.py"),
             workflow_debug_jobstore(),
             "--logDebug",
             "--listFilesInJobStore=True",
@@ -86,7 +86,7 @@ def fetchFiles(symLink: bool, jobStoreDir: str, outputDir: str):
     contents = ["A.txt", "B.txt", "C.txt", "ABC.txt", "mkFile.py"]
     cmd = [
         python,
-        os.path.abspath("src/toil/utils/toilDebugFile.py"),
+        get_data("toil/utils/toilDebugFile.py"),
         jobStoreDir,
         "--fetch",
         "*A.txt",
@@ -137,7 +137,7 @@ class DebugJobTest(ToilTest):
             subprocess.check_call(
                 [
                     python,
-                    os.path.abspath("src/toil/test/docs/scripts/example_alwaysfail.py"),
+                    get_data("toil/test/docs/scripts/example_alwaysfail.py"),
                     "--retryCount=0",
                     "--logCritical",
                     "--disableProgress",
@@ -172,9 +172,7 @@ class DebugJobTest(ToilTest):
         wf_result = subprocess.run(
             [
                 "toil-wdl-runner",
-                os.path.abspath(
-                    "src/toil/test/docs/scripts/example_alwaysfail_with_files.wdl"
-                ),
+                get_data("toil/test/docs/scripts/example_alwaysfail_with_files.wdl"),
                 "--retryCount=0",
                 "--logDebug",
                 "--disableProgress",
diff --git a/src/toil/test/utils/toilKillTest.py b/src/toil/test/utils/toilKillTest.py
index 1f8ef4b..a0037e2 100644
--- a/src/toil/test/utils/toilKillTest.py
+++ b/src/toil/test/utils/toilKillTest.py
@@ -23,7 +23,7 @@ import unittest
 from toil.common import Toil
 from toil.jobStores.abstractJobStore import NoSuchFileException, NoSuchJobStoreException
 from toil.jobStores.utils import generate_locator
-from toil.test import ToilTest, needs_aws_s3, needs_cwl
+from toil.test import ToilTest, get_data, needs_aws_s3, needs_cwl
 
 logger = logging.getLogger(__name__)
 
@@ -40,8 +40,8 @@ class ToilKillTest(ToilTest):
 
     def setUp(self):
         """Shared test variables."""
-        self.cwl = os.path.abspath("src/toil/test/utils/ABCWorkflowDebug/sleep.cwl")
-        self.yaml = os.path.abspath("src/toil/test/utils/ABCWorkflowDebug/sleep.yaml")
+        self.cwl = get_data("toil/test/utils/ABCWorkflowDebug/sleep.cwl")
+        self.yaml = get_data("toil/test/utils/ABCWorkflowDebug/sleep.yaml")
 
     def tearDown(self):
         """Default tearDown for unittest."""
@@ -90,8 +90,8 @@ class ToilKillTest(ToilTest):
 class ToilKillTestWithAWSJobStore(ToilKillTest):
     """A set of test cases for "toil kill" using the AWS job store."""
 
-    def __init__(self, *args, **kwargs):
-        super().__init__(*args, **kwargs)
+    def setUp(self):
+        super().setUp()
         self.job_store = generate_locator("aws", decoration="testkill")
 
 
diff --git a/src/toil/test/utils/utilsTest.py b/src/toil/test/utils/utilsTest.py
index 1525f44..92d3e85 100644
--- a/src/toil/test/utils/utilsTest.py
+++ b/src/toil/test/utils/utilsTest.py
@@ -33,6 +33,7 @@ from toil.job import Job
 from toil.lib.bioio import system
 from toil.test import (
     ToilTest,
+    get_data,
     get_temp_file,
     integrative,
     needs_aws_ec2,
@@ -444,10 +445,10 @@ class UtilsTest(ToilTest):
             self.toilDir,
             "--clean=never",
             "--badWorker=1",
-            "src/toil/test/cwl/sorttool.cwl",
+            get_data("toil/test/cwl/sorttool.cwl"),
             "--reverse",
             "--input",
-            "src/toil/test/cwl/whale.txt",
+            get_data("toil/test/cwl/whale.txt"),
             f"--outdir={self.tempDir}",
         ]
         logger.info("Run command: %s", " ".join(cmd))
@@ -465,10 +466,10 @@ class UtilsTest(ToilTest):
             "--jobStore",
             self.toilDir,
             "--clean=never",
-            "src/toil/test/cwl/sorttool.cwl",
+            get_data("toil/test/cwl/sorttool.cwl"),
             "--reverse",
             "--input",
-            "src/toil/test/cwl/whale.txt",
+            get_data("toil/test/cwl/whale.txt"),
             f"--outdir={self.tempDir}",
         ]
         wf = subprocess.Popen(cmd)
@@ -487,7 +488,7 @@ class UtilsTest(ToilTest):
             "--jobStore",
             self.toilDir,
             "--clean=never",
-            "src/toil/test/cwl/alwaysfails.cwl",
+            get_data("toil/test/cwl/alwaysfails.cwl"),
             "--message",
             "Testing",
         ]
diff --git a/src/toil/test/wdl/wdltoil_test.py b/src/toil/test/wdl/wdltoil_test.py
index 68beb2b..8b34061 100644
--- a/src/toil/test/wdl/wdltoil_test.py
+++ b/src/toil/test/wdl/wdltoil_test.py
@@ -1,7 +1,6 @@
 import json
 import logging
 import os
-import pytest
 import re
 import shutil
 import string
@@ -11,12 +10,14 @@ from typing import Any, Optional, Union
 from unittest.mock import patch
 from uuid import uuid4
 
+import pytest
 import WDL.Error
 import WDL.Expr
 
 from toil.fileStores import FileID
 from toil.test import (
     ToilTest,
+    get_data,
     needs_docker,
     needs_docker_cuda,
     needs_google_storage,
@@ -203,8 +204,8 @@ class WDLTests(BaseWDLTest):
     def test_MD5sum(self):
         """Test if Toil produces the same outputs as known good outputs for WDL's
         GATK tutorial #1."""
-        wdl = os.path.abspath("src/toil/test/wdl/md5sum/md5sum.1.0.wdl")
-        json_file = os.path.abspath("src/toil/test/wdl/md5sum/md5sum.json")
+        wdl = get_data("toil/test/wdl/md5sum/md5sum.1.0.wdl")
+        json_file = get_data("toil/test/wdl/md5sum/md5sum.json")
 
         result_json = subprocess.check_output(
             self.base_command
@@ -221,7 +222,7 @@ class WDLTests(BaseWDLTest):
         """
         Test if web URL strings can be coerced to usable Files.
         """
-        wdl = os.path.abspath("src/toil/test/wdl/testfiles/url_to_file.wdl")
+        wdl = get_data("toil/test/wdl/testfiles/url_to_file.wdl")
 
         result_json = subprocess.check_output(
             self.base_command
@@ -238,7 +239,7 @@ class WDLTests(BaseWDLTest):
         """
         Test if Bash "wait" works in WDL scripts.
         """
-        wdl = os.path.abspath("src/toil/test/wdl/testfiles/wait.wdl")
+        wdl = get_data("toil/test/wdl/testfiles/wait.wdl")
 
         result_json = subprocess.check_output(
             self.base_command
@@ -262,7 +263,7 @@ class WDLTests(BaseWDLTest):
         """
         Test if Toil can collect all call outputs from a workflow that doesn't expose them.
         """
-        wdl = os.path.abspath("src/toil/test/wdl/testfiles/not_enough_outputs.wdl")
+        wdl = get_data("toil/test/wdl/testfiles/not_enough_outputs.wdl")
 
         # With no flag we don't include the call outputs
         result_json = subprocess.check_output(
@@ -319,7 +320,7 @@ class WDLTests(BaseWDLTest):
         """
         Test if Toil can detect and do something sensible with Cromwell Output Organizer workflows.
         """
-        wdl = os.path.abspath("src/toil/test/wdl/testfiles/croo.wdl")
+        wdl = get_data("toil/test/wdl/testfiles/croo.wdl")
 
         # With no flag we should include all task outputs
         result_json = subprocess.check_output(
@@ -357,7 +358,7 @@ class WDLTests(BaseWDLTest):
         """
         Test if Toil can cache task runs.
         """
-        wdl = os.path.abspath('src/toil/test/wdl/testfiles/random.wdl')
+        wdl = get_data("toil/test/wdl/testfiles/random.wdl")
 
         caching_env = dict(os.environ)
         caching_env["MINIWDL__CALL_CACHE__GET"] = "true"
@@ -412,7 +413,7 @@ class WDLTests(BaseWDLTest):
         """
         Test if missing and error-producing URLs are handled correctly for optional File? values.
         """
-        wdl = os.path.abspath("src/toil/test/wdl/testfiles/url_to_optional_file.wdl")
+        wdl = get_data("toil/test/wdl/testfiles/url_to_optional_file.wdl")
 
         def run_for_code(code: int) -> dict:
             """
@@ -457,8 +458,8 @@ class WDLTests(BaseWDLTest):
         """
         Test if Toil can run a WDL workflow into a new directory.
         """
-        wdl = os.path.abspath("src/toil/test/wdl/md5sum/md5sum.1.0.wdl")
-        json_file = os.path.abspath("src/toil/test/wdl/md5sum/md5sum.json")
+        wdl = get_data("toil/test/wdl/md5sum/md5sum.1.0.wdl")
+        json_file = get_data("toil/test/wdl/md5sum/md5sum.json")
         subprocess.check_call(
             self.base_command
             + [
@@ -474,8 +475,8 @@ class WDLTests(BaseWDLTest):
     @needs_singularity_or_docker
     def test_miniwdl_self_test(self, extra_args: Optional[list[str]] = None) -> None:
         """Test if the MiniWDL self test runs and produces the expected output."""
-        wdl_file = os.path.abspath("src/toil/test/wdl/miniwdl_self_test/self_test.wdl")
-        json_file = os.path.abspath("src/toil/test/wdl/miniwdl_self_test/inputs.json")
+        wdl_file = get_data("toil/test/wdl/miniwdl_self_test/self_test.wdl")
+        json_file = get_data("toil/test/wdl/miniwdl_self_test/inputs.json")
 
         result_json = subprocess.check_output(
             self.base_command
@@ -656,8 +657,8 @@ class WDLTests(BaseWDLTest):
     @needs_google_storage
     def test_gs_uri(self):
         """Test if Toil can access Google Storage URIs."""
-        wdl = os.path.abspath("src/toil/test/wdl/md5sum/md5sum.1.0.wdl")
-        json_file = os.path.abspath("src/toil/test/wdl/md5sum/md5sum-gs.json")
+        wdl = get_data("toil/test/wdl/md5sum/md5sum.1.0.wdl")
+        json_file = get_data("toil/test/wdl/md5sum/md5sum-gs.json")
 
         result_json = subprocess.check_output(
             self.base_command + [wdl, json_file, "-o", self.output_dir, "--logDebug"]
