Note that there are some explanatory texts on larger screens.

plurals
  1. POtemporary TEMPLATE_DIRS override for testing does not work
    primarykey
    data
    text
    <p>For testing a custom templatetag i need to test a function that returns a rendered template. To be able to compare the output without having to know about the user-generated production template (which is going to change every now and then), i try to override the TEMPLATE_DIRS setting. Looks like a perfect use-scenario for the new override_settings decorator of Django 1.4:</p> <pre><code>@override_settings(TEMPLATE_DIRS='%s/templates' % os.path.abspath(os.path.dirname(__file__)) ) def test_render_as_list(self): self.node.type = 'list' self.node.listtemplate = 'testtemplate.html' self.node.items = ['a', 'b', 'c'] # these lines print the correct path to the template from django.conf import settings print(settings.TEMPLATE_DIRS) # inserted debug trace here import ipdb;ipdb.set_trace() response = render_as_list(self.node, self.context) self.assertEqual(response,'item a, item b, item c') </code></pre> <p>This is what my directory structure looks like:</p> <pre><code>- project - app_to_test - fixtures - templatetags - tests __init__.py test_templatetags.py (containing the test shown above) templates testtemplate.html </code></pre> <p>As far as i understand my code, the settings.TEMPLATE_DIRS should now point to</p> <pre><code>/some/path/project/app_to_test/tests/templates </code></pre> <p>The lines to print the new settings.TEMPLATE_DIRS value show that the decorator worked, but still the render_as_list function returns </p> <blockquote> <p>TemplateDoesNotExist: testtemplate.html</p> </blockquote> <p>I'm stuck with that since hours now, and just can't find what else to try.</p> <p><strong>edit:</strong> path creation is working, the file exists, but Django still doesn't load the template:</p> <pre><code>ipdb&gt; from django.conf import settings ipdb&gt; path = settings.TEMPLATE_DIRS ipdb&gt; templatename = path+'testtemplate.html' ipdb&gt; templatename '/Volumes/Data/project/my_app/tests/templates/testtemplate.html' ipdb&gt; template.loader.get_template(templatename) *** TemplateDoesNotExist: /Volumes/Data/project/my_app/tests/templates/testtemplate.html ipdb&gt; f = file(templatename) ipdb&gt; f &lt;open file '/Volumes/Data/project/my_app/tests/templates/testtemplate.html', mode 'r' at 0x102e95d78&gt; ipdb&gt; f.read() 'testtemplate content' </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload