def test_volatile_scoping(self): env = Environment(extensions=["jinja.ext.autoescape"]) tmplsource = """ {% autoescape val %} {% macro foo(x) %} [{{ x }}] {% endmacro %} {{ foo().__class__.__name__ }} {% endautoescape %} {{ '<testing>' }} """ tmpl = env.from_string(tmplsource) assert tmpl.render(val=True).split()[0] == "Markup" assert tmpl.render(val=False).split()[0] == text_type.__name__ # looking at the source we should see <testing> there in raw # (and then escaped as well) env = Environment(extensions=["jinja.ext.autoescape"]) pysource = env.compile(tmplsource, raw=True) assert "<testing>\\n" in pysource env = Environment(extensions=["jinja.ext.autoescape"], autoescape=True) pysource = env.compile(tmplsource, raw=True) assert "<testing>\\n" in pysource