Repository: nf-core/tools
Issue: modules create-test-yml broken for alternative remotes

This command is broken when running in a repo which is not the default `nf-core/modules` (or possibly a direct mirror of).

The underlying class does not currently take `--git-remote` in it's init and when selecting the module it uses `ModulesRepo()` which will always use the default NF-Core remote.   

tools 2.7dev0

Changed files:
nf_core/subworkflows/test_yml_builder.py, nf_core/modules/test_yml_builder.py, nf_core/__main__.py, tests/modules/create_test_yml.py

diff --git a/nf_core/__main__.py b/nf_core/__main__.py
index 2966f758..aaf0ea98 100644
--- a/nf_core/__main__.py
+++ b/nf_core/__main__.py
@@ -733,6 +733,8 @@ def create_test_yml(ctx, tool, run_tests, output, force, no_prompts):
             test_yml_output_path=output,
             force_overwrite=force,
             no_prompts=no_prompts,
+            remote_url=ctx.obj["modules_repo_url"],
+            branch=ctx.obj["modules_repo_branch"],
         )
         meta_builder.run()
     except (UserWarning, LookupError) as e:
@@ -979,6 +981,8 @@ def create_test_yml(ctx, subworkflow, run_tests, output, force, no_prompts):
             test_yml_output_path=output,
             force_overwrite=force,
             no_prompts=no_prompts,
+            remote_url=ctx.obj["modules_repo_url"],
+            branch=ctx.obj["modules_repo_branch"],
         )
         meta_builder.run()
     except (UserWarning, LookupError) as e:
diff --git a/nf_core/modules/test_yml_builder.py b/nf_core/modules/test_yml_builder.py
index cef23fb6..c9a6273a 100644
--- a/nf_core/modules/test_yml_builder.py
+++ b/nf_core/modules/test_yml_builder.py
@@ -40,9 +40,13 @@ class ModulesTestYmlBuilder(ComponentCommand):
         test_yml_output_path=None,
         force_overwrite=False,
         no_prompts=False,
+        remote_url=None,
+        branch=None,
     ):
-        super().__init__("modules", directory)
+        super().__init__("modules", directory, remote_url, branch)
         self.module_name = module_name
+        self.remote_url = remote_url
+        self.branch = branch
         self.run_tests = run_tests
         self.test_yml_output_path = test_yml_output_path
         self.force_overwrite = force_overwrite
@@ -75,10 +79,9 @@ class ModulesTestYmlBuilder(ComponentCommand):
 
         # Get the tool name if not specified
         if self.module_name is None:
-            modules_repo = ModulesRepo()
             self.module_name = questionary.autocomplete(
                 "Tool name:",
-                choices=modules_repo.get_avail_components(self.component_type),
+                choices=self.components_from_repo(self.org),
                 style=nf_core.utils.nfcore_question_style,
             ).unsafe_ask()
         self.module_dir = os.path.join(self.default_modules_path, *self.module_name.split("/"))
@@ -97,7 +100,7 @@ class ModulesTestYmlBuilder(ComponentCommand):
 
         # Get the output YAML file / check it does not already exist
         while self.test_yml_output_path is None:
-            default_val = f"tests/modules/nf-core/{self.module_name}/test.yml"
+            default_val = f"tests/modules/{self.org}/{self.module_name}/test.yml"
             if self.no_prompts:
                 self.test_yml_output_path = default_val
             else:
@@ -173,8 +176,8 @@ class ModulesTestYmlBuilder(ComponentCommand):
             # Don't think we need the last `-c` flag, but keeping to avoid having to update 100s modules.
             # See https://github.com/nf-core/tools/issues/1562
             default_val = (
-                f"nextflow run ./tests/modules/nf-core/{self.module_name} -entry {entry_point} "
-                f"-c ./tests/config/nextflow.config -c ./tests/modules/nf-core/{self.module_name}/nextflow.config"
+                f"nextflow run ./tests/modules/{self.org}/{self.module_name} -entry {entry_point} "
+                f"-c ./tests/config/nextflow.config -c ./tests/modules/{self.org}/{self.module_name}/nextflow.config"
             )
             if self.no_prompts:
                 ep_test["command"] = default_val
diff --git a/nf_core/subworkflows/test_yml_builder.py b/nf_core/subworkflows/test_yml_builder.py
index b2f6cd6c..3090b22c 100644
--- a/nf_core/subworkflows/test_yml_builder.py
+++ b/nf_core/subworkflows/test_yml_builder.py
@@ -42,10 +42,14 @@ class SubworkflowTestYmlBuilder(ComponentCommand):
         test_yml_output_path=None,
         force_overwrite=False,
         no_prompts=False,
+        remote_url=None,
+        branch=None,
     ):
         super().__init__("subworkflows", directory)
         self.dir = directory
         self.subworkflow = subworkflow
+        self.remote_url = remote_url
+        self.branch = branch
         self.run_tests = run_tests
         self.test_yml_output_path = test_yml_output_path
         self.force_overwrite = force_overwrite
@@ -55,7 +59,7 @@ class SubworkflowTestYmlBuilder(ComponentCommand):
         self.entry_points = []
         self.tests = []
         self.errors = []
-        self.modules_repo = ModulesRepo()
+        self.modules_repo = ModulesRepo(remote_url=self.remote_url, branch=self.branch)
         self.modules_json = ModulesJson(self.dir)
 
     def run(self):
@@ -78,7 +82,7 @@ class SubworkflowTestYmlBuilder(ComponentCommand):
         if self.subworkflow is None:
             self.subworkflow = questionary.autocomplete(
                 "Subworkflow name:",
-                choices=self.modules_repo.get_avail_components(self.component_type),
+                choices=self.components_from_repo(self.org),
                 style=nf_core.utils.nfcore_question_style,
             ).unsafe_ask()
         self.subworkflow_dir = os.path.join("subworkflows", self.modules_repo.repo_path, self.subworkflow)
diff --git a/tests/modules/create_test_yml.py b/tests/modules/create_test_yml.py
index b0d08792..d444ff84 100644
--- a/tests/modules/create_test_yml.py
+++ b/tests/modules/create_test_yml.py
@@ -1,10 +1,11 @@
 import os
+from pathlib import Path
 
 import pytest
 
 import nf_core.modules
 
-from ..utils import with_temporary_folder
+from ..utils import GITLAB_DEFAULT_BRANCH, GITLAB_URL, with_temporary_folder
 
 
 @with_temporary_folder
@@ -20,7 +21,7 @@ def test_modules_custom_yml_dumper(self, out_dir):
 
 @with_temporary_folder
 def test_modules_test_file_dict(self, test_file_dir):
-    """Creat dict of test files and create md5 sums"""
+    """Create dict of test files and create md5 sums"""
     meta_builder = nf_core.modules.ModulesTestYmlBuilder("test/tool", self.pipeline_dir, False, "./", False, True)
     with open(os.path.join(test_file_dir, "test_file.txt"), "w") as fh:
         fh.write("this line is just for testing")