Skip to content

--generate-unit-tests will raise error in 8.20.1 or newer version #3137

@jiangyun-fun

Description

@jiangyun-fun

Snakemake version

8.21.0
or
8.20.*
Describe the bug

Snakefile:

rule a:
    output:
        "test",
    shell:
        "touch {output} "

error:

❯ snakemake --generate-unit-tests
Found existing alias for "snakemake". You should use: "snk"
Building DAG of jobs...
Generating unit tests for each rule...
Traceback (most recent call last):

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/snakemake/cli.py", line 2053, in args_to_api
    dag_api.generate_unit_tests(args.generate_unit_tests)

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/snakemake/api.py", line 604, in _handle_no_exec
    return method(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/snakemake/api.py", line 616, in generate_unit_tests
    self.workflow_api._workflow.generate_unit_tests(path=path)

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/snakemake/workflow.py", line 828, in generate_unit_tests
    unit_tests.generate(

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/snakemake/unit_tests/__init__.py", line 52, in generate
    env.get_template("common.py.jinja2").render(version=__version__),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/jinja2/environment.py", line 1013, in get_template
    return self._load_template(name, globals)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/jinja2/environment.py", line 972, in _load_template
    template = self.loader.load(self, name, self.make_globals(globals))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/jinja2/loaders.py", line 126, in load
    source, filename, uptodate = self.get_source(environment, name)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/jinja2/loaders.py", line 347, in get_source
    raise TemplateNotFound(template)

jinja2.exceptions.TemplateNotFound: common.py.jinja2

Logs

❯ mamba create -n 20241013_test_snk snakemake
❯ mamba activate 20241013_test_snk
❯ snakemake --version
Found existing alias for "snakemake". You should use: "snk"                                                                                                                                                                                     8.21.0
❯ snakemake
Found existing alias for "snakemake". You should use: "snk"                                                                                                                                                                                     Assuming unrestricted shared filesystem usage.
Building DAG of jobs...
Using shell: /usr/bin/bash                                                                                                                                                                                                                      Provided cores: 16
Rules claiming more threads will be scaled down.                                                                                                                                                                                                Job stats:
job      count                                                                                                                                                                                                                                  -----  -------                                                                                                                                                                                                                                  a            1
total        1

Select jobs to execute...                                                                                                                                                                                                                       Execute 1 jobs...
                                                                                                                                                                                                                                                [Sun Oct 13 11:10:55 2024]                                                                                                                                                                                                                      localrule a:
    output: test
    jobid: 0
    reason: Missing output files: test
    resources: tmpdir=/tmp

[Sun Oct 13 11:10:55 2024]
Finished job 0.
1 of 1 steps (100%) done
Complete log: .snakemake/log/2024-10-13T111055.778607.snakemake.log
❯ snakemake --generate-unit-tests
Found existing alias for "snakemake". You should use: "snk"
Building DAG of jobs...
Generating unit tests for each rule...
Traceback (most recent call last):

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/snakemake/cli.py", line 2053, in args_to_api
    dag_api.generate_unit_tests(args.generate_unit_tests)

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/snakemake/api.py", line 604, in _handle_no_exec
    return method(self, *args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/snakemake/api.py", line 616, in generate_unit_tests
    self.workflow_api._workflow.generate_unit_tests(path=path)

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/snakemake/workflow.py", line 828, in generate_unit_tests
    unit_tests.generate(

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/snakemake/unit_tests/__init__.py", line 52, in generate
    env.get_template("common.py.jinja2").render(version=__version__),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/jinja2/environment.py", line 1013, in get_template
    return self._load_template(name, globals)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/jinja2/environment.py", line 972, in _load_template
    template = self.loader.load(self, name, self.make_globals(globals))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/jinja2/loaders.py", line 126, in load
    source, filename, uptodate = self.get_source(environment, name)
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  File "/home/jiangy/1/miniforge3/envs/20241013_test_snk/lib/python3.12/site-packages/jinja2/loaders.py", line 347, in get_source
    raise TemplateNotFound(template)

jinja2.exceptions.TemplateNotFound: common.py.jinja2

Additional context

In version 8.20.1 will also raise error:

❯ mamba install -y snakemake=8.20.1
❯ snakemake --version
Found existing alias for "snakemake". You should use: "snk"
8.20.1
❯ snakemake --generate-unit-tests                                                                                                                                                                                    Found existing alias for "snakemake". You should use: "snk"
Building DAG of jobs...
Generating unit tests for each rule...
Traceback (most recent call last):
.....
jinja2.exceptions.TemplateNotFound: common.py.jinja2

In 8.18.1, it works well.

❯ mamba install -y snakemake=8.18.1
❯ snakemake --version
Found existing alias for "snakemake". You should use: "snk"
8.18.1
❯ snakemake --generate-unit-tests
Found existing alias for "snakemake". You should use: "snk"
Building DAG of jobs...
Generating unit tests for each rule...
Generating unit test for rule a: .tests/unit/test_a.py.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions