]> git.ipfire.org Git - thirdparty/jinja.git/commitdiff
clean up message, add test 1663/head
authorDavid Lord <davidism@gmail.com>
Fri, 20 Dec 2024 03:34:34 +0000 (19:34 -0800)
committerDavid Lord <davidism@gmail.com>
Fri, 20 Dec 2024 03:34:34 +0000 (19:34 -0800)
CHANGES.rst
src/jinja2/loaders.py
tests/test_loader.py

index 569ae69f778cf72fcd5e03eb33fff551eb383bcd..cd2a4ef089f14fefee9c74d8c4ca69d231d8d26d 100644 (file)
@@ -35,8 +35,8 @@ Unreleased
 -   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
index 65dfbe1a0eaed79297fc3ba5e942cce2dcdabdf6..35799584cbf4c6ef35b5bd7494eb0c0094c566ae 100644 (file)
@@ -204,9 +204,11 @@ class FileSystemLoader(BaseLoader):
             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:
index e0cff6720fd27e8eb9906dccb36c80b74bd49f58..5a4e1a9daf07e230b0f2c75741e35c55220cb128 100644 (file)
@@ -179,6 +179,24 @@ class TestFileSystemLoader:
         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