Is it possible to set a NF environment variable su...
# nextflow-plugins
j
Is it possible to set a NF environment variable such as
NXF_PARAMS_FILE
from a Gradle test?
🤔 1
so far I have tried this, but I doesn’t seem to work
Copy code
def 'test name' () {
        given:
        def ENV = [NXF_PARAMS_FILE: 'src/testResources/nested_paramteres.yml']
        def  SCRIPT_TEXT = """
            println(params.baz)
            println(params.foo)
        """

        when:
        dsl_eval(SCRIPT_TEXT)

        then:
        !stdout
    }
Also found the environment property but it’s not clear how I should use it. I have
environment "NXF_PARAMS_FILE", 'src/testResources/nested_paramteres.yml'
and get the error
groovy.lang.MissingMethodException: No signature of method: nextflow.validation.PluginExtensionMethodsTest.environment() is applicable for argument types: (String, String) values: [NXF_PARAMS_FILE, src/testResources/nested_paramteres.yml]
m
This is a Spock test, right? If so, I think so. There should be examples in the nextflow codebase
j
do you know where could I find the examples? My first try is based on this but I think I am missing something here 🤔
j
thank you 🙂
m
You’re welcome 😄
j
this was very useful! But now I can’t access these params from inside my script
SCRIPT_TEXT
😞
Copy code
def 'test name' () {
        given:
	def folder = Files.createTempDirectory('test')
        def YAML = '''
            foo: bar
            baz:
                qux: corge
                grault: garply
            '''.stripIndent()
        def  SCRIPT_TEXT = """
            println(params.baz)
            println(params.foo)
        """

        when:
        def file = folder.resolve('params.yaml')
	file.text = YAML
	and:
        def cmd = new CmdRun(sysEnv: [NXF_PARAMS_FILE: file.toString()])
        def params = cmd.parsedParams()
        dsl_eval(SCRIPT_TEXT)

        then:
	params.foo == "bar" 
}
This is what I have now, this test passes because
params.foo == "bar"
but I need these params available inside my script for some checks. Also tried adding something like
session.params = params
and got an error
Cannot set readonly property: params for class: test.MockSession
Someone knows how could I achieve this?
I opened a PR in case it’s useful for more context
m
😕
Sorry, don’t know how to help