Migrating from pytest to nf-test
Checkout a new branch for your module/subworkflow tests.
git switch <branch>To create the necessary files for nf-test and ensure a smooth transition, we will use the template provided by nf-core/tools.
Here are the steps to follow:
- Use nf-core/tools to migrate the module/subworkflow with
--migrate-pytest.
nf-core modules create <tool>/<subtool> --migrate-pytestThis command will:
-
rename the current module directory to
<module>_oldto avoid conflicts with the new module, -
create a new module named
<module>, based on the nf-test template. -
copy the
main.nf,meta.ymlandenvironment.ymlfiles over to preserve the original module code. -
(optional) If your module has a
nextflow.configfile to run (e.g. forext.argsspecification), the command will also copy it to the module’stests/directory and the path will be added to themain.nf.testfile.main.nf.test process "MODULE" config "./nextflow.config"
nf-core subworkflows create <subworkflow> --migrate-pytestThis command will:
- rename the current subworkflow directory to
<subworkflow>_oldto avoid conflicts with the new subworkflow, - create a new subworkflow named
<subworkflow>based on the nf-test template. - copy the
main.nfandmeta.ymlfiles over to preserve the original subworkflow code.
-
You will then be asked if you want to delete the old files or keep them. No worries, we will print the content of the old pytests in the terminal so you can copy the information to the new nf-test files.
-
Copy the inputs from the pytests and provide them as positional inputs
input[0]in themain.nf.testfilemain.nf.test input[0] = [ [id:"ref"], file(params.modules_testdata_base_path + 'genomics/homo_sapiens/genome/genome.fasta.fai', checkIfExists: true) ] -
Follow the steps in the tutorial for writing nf-tests to update the contents of the
main.nf.testfile with the information from the pytest tests. -
Create the snapshot of your test with the following command.
nf-core modules test <tool>/<subtool>nf-core subworkflows test <tool>/<subtool>- If you chose to not remove the old module directory with nf-core/tools:
- Remove the corresponding tags from
tests/config/pytest_modules.ymlso that py-tests for the module/subworkflow will be skipped during GitHub CI.
- Remove the corresponding tags from
- Remove the corresponding pytest files in
tests/modules/nf-core
rm -r tests/modules/nf-core/<tool>/<subtool>- Remove the old module
rm -r modules/nf-core/<tool>/<subtool>_old- Check if everything is according to the nf-core guidelines with:
nf-core modules lint <tool>/<subtool>- Remove the corresponding pytest files in
tests/subworkflows/nf-core
rm -r tests/subworkflows/nf-core/<subworkflow>- Remove the old subworkflow
rm -r subworkflows/nf-core/<subworkflow>_old- Check if everything is according to the nf-core guidelines with:
nf-core subworkflows lint <subworkflow>- create a PR on the nf-core/modules repo and add the
nf-testlabel to it.