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/5305
Last-Update: 2025-05-05
---
 MANIFEST.in                                    |  9 +++++++++
 src/toil/test/docs/scripts/tutorial_staging.py | 10 ++++------
 2 files changed, 13 insertions(+), 6 deletions(-)

--- toil.orig/src/toil/test/utils/toilKillTest.py
+++ toil/src/toil/test/utils/toilKillTest.py
@@ -87,6 +87,7 @@
     """A set of test cases for "toil kill"."""
 
     @needs_cwl
+    @needs_aws_s3
     def test_cwl_toil_kill(self, tmp_path: Path) -> None:
         """Test "toil kill" on a CWL workflow with a 100 second sleep."""
         self._test_cwl_toil_kill(str(tmp_path / "job_store"))
--- toil.orig/src/toil/test/src/resourceTest.py
+++ toil/src/toil/test/src/resourceTest.py
@@ -155,8 +155,6 @@
         # Assert basic attributes and properties
         assert module.belongsToToil == shouldBelongToToil
         assert module.name == module_name
-        if shouldBelongToToil:
-            assert module.dirPath.endswith("/src")
 
         # Before the module is saved as a resource, localize() and globalize() are identity
         # methods. This should log.warnings.
--- toil.orig/src/toil/cwl/cwltoil.py
+++ toil/src/toil/cwl/cwltoil.py
@@ -5257,15 +5257,6 @@
 
     loading_context = cwltool.main.setup_loadingContext(None, runtime_context, options)
 
-    if options.provenance:
-        research_obj = cwltool.cwlprov.ro.ResearchObject(
-            temp_prefix_ro=tmp_outdir_prefix,
-            orcid=options.orcid,
-            full_name=options.cwl_full_name,
-            fsaccess=runtime_context.make_fs_access(""),
-        )
-        runtime_context.research_obj = research_obj
-
     try:
 
         # We might have workflow metadata to pass to Toil
@@ -5363,12 +5354,6 @@
 
             document_loader = loading_context.loader
 
-            if options.provenance and runtime_context.research_obj:
-                cwltool.cwlprov.writablebagfile.packed_workflow(
-                    runtime_context.research_obj,
-                    cwltool.main.print_pack(loading_context, uri),
-                )
-
             try:
                 tool = cwltool.load_tool.make_tool(uri, loading_context)
                 scan_for_unsupported_requirements(
@@ -5509,40 +5494,6 @@
             )
             logger.info("Stored workflow outputs")
 
-            if runtime_context.research_obj is not None:
-                cwltool.cwlprov.writablebagfile.create_job(
-                    runtime_context.research_obj, outobj, True
-                )
-
-                def remove_at_id(doc: Any) -> None:
-                    if isinstance(doc, MutableMapping):
-                        for key in list(doc.keys()):
-                            if key == "@id":
-                                del doc[key]
-                            else:
-                                value = doc[key]
-                                if isinstance(value, MutableMapping):
-                                    remove_at_id(value)
-                                if isinstance(value, MutableSequence):
-                                    for entry in value:
-                                        if isinstance(value, MutableMapping):
-                                            remove_at_id(entry)
-
-                remove_at_id(outobj)
-                visit_class(
-                    outobj,
-                    ("File",),
-                    functools.partial(add_sizes, runtime_context.make_fs_access("")),
-                )
-                if not document_loader:
-                    raise RuntimeError("cwltool loader is not set.")
-                prov_dependencies = cwltool.main.prov_deps(
-                    workflowobj, document_loader, uri
-                )
-                runtime_context.research_obj.generate_snapshot(prov_dependencies)
-                cwltool.cwlprov.writablebagfile.close_ro(
-                    runtime_context.research_obj, options.provenance
-                )
 
             if not options.destBucket and options.compute_checksum:
                 logger.info("Computing output file checksums...")
--- toil.orig/src/toil/test/lib/aws/test_s3.py
+++ toil/src/toil/test/lib/aws/test_s3.py
@@ -17,7 +17,6 @@
 from typing import TYPE_CHECKING, Optional
 
 from toil.lib.aws.session import establish_boto3_session
-from toil.lib.aws.s3 import create_s3_bucket, delete_s3_bucket
 from toil.lib.aws.utils import get_bucket_region
 from toil.test import ToilTest, needs_aws_s3
 
@@ -43,6 +42,7 @@
 
     def test_create_bucket(self) -> None:
         """Test bucket creation for us-east-1."""
+        from toil.lib.aws.s3 import create_s3_bucket, delete_s3_bucket
         bucket_name = f"toil-s3test-{uuid.uuid4()}"
         assert self.s3_resource
         bucket: Optional["Bucket"] = None
--- toil.orig/src/toil/test/provisioners/aws/awsProvisionerTest.py
+++ toil/src/toil/test/provisioners/aws/awsProvisionerTest.py
@@ -32,7 +32,6 @@
     get_aws_zone_from_spot_market,
     get_best_aws_zone,
 )
-from toil.provisioners.aws.awsProvisioner import AWSProvisioner
 from toil.test import (
     get_data,
     integrative,
@@ -95,6 +94,7 @@
 
     # Needs to talk to EC2 for image discovery
     def test_AMI_finding(self):
+        from toil.provisioners.aws.awsProvisioner import AWSProvisioner
         for zone in ["us-west-2a", "eu-central-1a", "sa-east-1b"]:
             provisioner = AWSProvisioner(
                 "fakename", "mesos", zone, 10000, None, None, enable_fuse=False
@@ -109,6 +109,7 @@
         Make sure the `_write_file_to_cloud()` and `_read_file_from_cloud()`
         functions of the AWS provisioner work as intended.
         """
+        from toil.provisioners.aws.awsProvisioner import AWSProvisioner
         provisioner = AWSProvisioner(
             f"aws-provisioner-test-{uuid4()}",
             "mesos",
--- toil.orig/MANIFEST.in
+++ toil/MANIFEST.in
@@ -3,8 +3,11 @@
 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/cwl/mock_mpi/fake_mpi_run.py
 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
+recursive-include src/toil/test/ *.json
+graft src/toil/test/cwl/test_filename_conflict_resolution.ms
--- toil.orig/src/toil/test/cwl/mpi_simple.cwl
+++ toil/src/toil/test/cwl/mpi_simple.cwl
@@ -10,7 +10,7 @@
   processes. Requires Python (but you have cwltool running, right?)
   and an MPI implementation.
 
-baseCommand: python
+baseCommand: python3
 requirements:
   cwltool:MPIRequirement:
     processes: 2
--- toil.orig/src/toil/test/cwl/cwlTest.py
+++ toil/src/toil/test/cwl/cwlTest.py
@@ -2033,7 +2033,7 @@
                 str(msin),
             ]
             p = subprocess.run(cmd, capture_output=True, text=True)
-            assert "Finished toil run successfully" in p.stderr
+            assert "Finished toil run successfully" in p.stderr, p
             assert p.returncode == 0
 
 
--- toil.orig/src/toil/test/cwl/test_filename_conflict_resolution.cwl
+++ toil/src/toil/test/cwl/test_filename_conflict_resolution.cwl
@@ -1,7 +1,7 @@
 cwlVersion: v1.2
 class: CommandLineTool
 baseCommand:
-  - python
+  - python3
   - copier.py
 
 requirements:
--- toil.orig/src/toil/test/jobStores/jobStoreTest.py
+++ toil/src/toil/test/jobStores/jobStoreTest.py
@@ -1879,7 +1879,7 @@
         assert "wdl" in result
 
 
-# @needs_aws_s3
+@needs_aws_s3
 class InvalidAWSJobStoreTest(ToilTest):
     def testInvalidJobStoreName(self):
         from toil.jobStores.aws.jobStore import AWSJobStore
