- Fix `copy`/`pickle` support for the internal ``missing`` object.
:issue:`2027`
- ``Environment.overlay(enable_async)`` is applied correctly. :pr:`2061`
-- Paths where the loader searched for the template were added
- to the error message. :issue:`1661`
+- The error message from ``FileSystemLoader`` includes the paths that were
+ searched. :issue:`1661`
Version 3.1.4
if os.path.isfile(filename):
break
else:
+ plural = "path" if len(self.searchpath) == 1 else "paths"
+ paths_str = ", ".join(repr(p) for p in self.searchpath)
raise TemplateNotFound(
- f"{template} not found in the following search path(s):"
- f" {self.searchpath}"
+ template,
+ f"{template!r} not found in search {plural}: {paths_str}",
)
with open(filename, encoding=self.encoding) as f:
t = e.get_template("foo/test.html")
assert t.filename == str(self.searchpath / "foo" / "test.html")
+ def test_error_includes_paths(self, env, filesystem_loader):
+ env.loader = filesystem_loader
+
+ with pytest.raises(TemplateNotFound) as info:
+ env.get_template("missing")
+
+ e_str = str(info.value)
+ assert e_str.startswith("'missing' not found in search path: ")
+
+ filesystem_loader.searchpath.append("other")
+
+ with pytest.raises(TemplateNotFound) as info:
+ env.get_template("missing")
+
+ e_str = str(info.value)
+ assert e_str.startswith("'missing' not found in search paths: ")
+ assert ", 'other'" in e_str
+
class TestModuleLoader:
archive = None