diff --git a/test/unit/util/test_fill_template.py b/test/unit/util/test_fill_template.py index 883040b86775..15c708030926 100644 --- a/test/unit/util/test_fill_template.py +++ b/test/unit/util/test_fill_template.py @@ -1,8 +1,15 @@ +import sys + import pytest from Cheetah.NameMapper import NotFound from galaxy.util.template import fill_template +# In Python 3.12 calling `locals()`` inside a comprehension now includes +# variables from outside the comprehension, see +# https://docs.python.org/dev/whatsnew/3.12.html#pep-709-comprehension-inlining +PY312_OR_LATER = sys.version_info[:2] >= (3, 12) + SIMPLE_TEMPLATE = """#for item in $a_list: echo $item #end for @@ -48,8 +55,12 @@ def test_fill_simple_template(): def test_fill_list_comprehension_template(): - with pytest.raises(NotFound): - fill_template(LIST_COMPREHENSION_TEMPLATE, retry=0) + if PY312_OR_LATER: + template_str = fill_template(LIST_COMPREHENSION_TEMPLATE, retry=0) + assert template_str == "echo 1\n" + else: + with pytest.raises(NotFound): + fill_template(LIST_COMPREHENSION_TEMPLATE, retry=0) def test_fill_list_comprehension_template_2(): @@ -58,13 +69,21 @@ def test_fill_list_comprehension_template_2(): def test_fill_dict_comprehension(): - with pytest.raises(NotFound): - fill_template(DICT_COMPREHENSION_TEMPLATE, retry=1) + if PY312_OR_LATER: + template_str = fill_template(DICT_COMPREHENSION_TEMPLATE, retry=1) + assert template_str == "echo 1\n" + else: + with pytest.raises(NotFound): + fill_template(DICT_COMPREHENSION_TEMPLATE, retry=1) def test_set_comprehension(): - with pytest.raises(NotFound): - fill_template(SET_COMPR_TEMPLATE, retry=1) + if PY312_OR_LATER: + template_str = fill_template(SET_COMPR_TEMPLATE, retry=1) + assert template_str == "echo 1\n" + else: + with pytest.raises(NotFound): + fill_template(SET_COMPR_TEMPLATE, retry=1) def test_gen_expr():