Skip to content

Don't execute cleanup on dry run#330

Open
prototaxites wants to merge 2 commits intoaskimed:mainfrom
prototaxites:cleanup_fix
Open

Don't execute cleanup on dry run#330
prototaxites wants to merge 2 commits intoaskimed:mainfrom
prototaxites:cleanup_fix

Conversation

@prototaxites
Copy link
Copy Markdown

Hi, thanks for the fantastic software!

We are running into a small problem with nf-test where we are including the cleanup block in tests. The cleanup block is always executed, which means that exceptions thrown in the block stop the dry run - we are running into this problem with this test (https://github.com/sanger-tol/nf-core-modules/blob/main/modules/sanger-tol/hiccramalign/minimap2align/tests/main.nf.test) where we are using some functions from nft-utils to cleanup a temporary modules library that is initialised in the setup block.

This PR just moves the cleanup line into the section that checks if a dry run is being executed, which should side-step the problem. Not sure if this is the optimal way to do this, so happy to discuss :)

@lukfor
Copy link
Copy Markdown
Collaborator

lukfor commented Sep 30, 2025

Thanks! 🙏🏼

@nvnieuwk
Copy link
Copy Markdown
Collaborator

Hi @prototaxites what exceptions are thrown in the setup block?

@prototaxites
Copy link
Copy Markdown
Author

That should say exceptions thrown in the cleanup block... 🤦‍♂️

See https://github.com/sanger-tol/nf-core-modules/blob/main/subworkflows/sanger-tol/cram_map_illumina_hic/tests/main.nf.test for an example - in the setup block we initialise a bunch of files, and then in the cleanup function we run a function that does stuff with those initialised files.

I ended up fixing the function (nfcoreUnlink) but previously it threw an exception if the setup block had not been run first.

@nvnieuwk
Copy link
Copy Markdown
Collaborator

That should say exceptions thrown in the cleanup block... 🤦‍♂️

Yeah that's what I meant 😅, could you provide some small reproducible example? I want to be sure that this is not a deeper problem first

@prototaxites
Copy link
Copy Markdown
Author

prototaxites commented Mar 17, 2026

main.nf.test:

nextflow_process {

    name "Test Process TEST_MODULE"
    script "./main.nf"
    process "TEST_MODULE"

    tag "test"

    test("test plugin") {

        setup {
            def check_file = new File("${launchDir}/check")
			check_file.text = "hello world"
        }

        then {
            assert process.success
        }
        cleanup {
            def check_file = new File("${launchDir}/check")
            if(!check_file.exists()) {
                throw new Exception("This block should only be seen if setup was not run (i.e. in a dry run)")
            }
        }
    }
}

Testing the following dummy module:

process TEST_MODULE {
    output:
    path ("test.txt"), emit: output

    script:
    """
    echo "hello!" > test.txt
    """
}

Normal run:

> nf-test test main.nf.test

🚀 nf-test 0.9.4
https://www.nf-test.com
(c) 2021 - 2024 Lukas Forer and Sebastian Schoenherr

Warning: This pipeline has no nf-test config file.

Test Process TEST_MODULE

  Test [d53f7783] 'test plugin' PASSED (2.379s)


SUCCESS: Executed 1 tests in 2.381s

Dry run:

> nf-test test main.nf.test --dry-run

🚀 nf-test 0.9.4
https://www.nf-test.com
(c) 2021 - 2024 Lukas Forer and Sebastian Schoenherr

Warning: This pipeline has no nf-test config file.
Dry run mode activated: tests are not executed, just listed.

Test Process TEST_MODULE

  Test [d53f7783] 'test plugin' Error: java.lang.Exception: This block should only be seen if setup was not run (i.e. in a dry run)

@lukfor
Copy link
Copy Markdown
Collaborator

lukfor commented Mar 17, 2026

I haven’t checked the code closely for side effects yet, but it makes sense to me that cleanup behaves the same way as setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants