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-pytest
    Technical details

    This command will:

    • rename the current module directory to <module>_old to avoid conflicts with the new module,

    • create a new module named <module>, based on the nf-test template.

    • copy the main.nf, meta.yml and environment.yml files over to preserve the original module code.

    • (optional) If your module has a nextflow.config file to run (e.g. for ext.args specification), the command will also copy it to the module’s tests/ directory and the path will be added to the main.nf.test file.

      main.nf.test
      process "MODULE"
      config "./nextflow.config"
    nf-core subworkflows create <subworkflow> --migrate-pytest
    Technical details

    This command will:

    • rename the current subworkflow directory to <subworkflow>_old to avoid conflicts with the new subworkflow,
    • create a new subworkflow named <subworkflow> based on the nf-test template.
    • copy the main.nf and meta.yml files 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 the main.nf.test file

    main.nf.test
    input[0] = [
                [id:"ref"],
                file(params.test_data['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.test file 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.yml so that py-tests for the module/subworkflow will be skipped during GitHub CI.
    • 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-test label to it.