Django test client ignores “include” terms in Django template












1















I have an issue with Django tests client.
Let for the home path I have this template (home.html):



<html>
<body>
{% include 'example.html' %}
</body>
</html>


and in example.html I have error:



<div>
{% non_registered_tag arg1 arg2 %}
</div>


I wrote a test for accessibility to a Django URL.



class HomePageAccess(TestCase):
def test_home_page(self):
client = Client()
response = client.get(reverse_lazy('home'))
self.assertEqual(response.status_code, 200)


This code fails successfully if there be an error in home.html, But if there be an error in example.html which is included in home.html Test will pass even though we expect to fail because I included it in home.html and in the browser I encounter an error (status code 500) while this not happens in test client.



Is it normal? I'm using Django 2.0.2.
Any help will be appreciated










share|improve this question




















  • 1





    In your settings.py do you have the debug option set in the OPTIONS dictionary of the TEMPLATES setting? And also what is the value of the overall DEBUG setting in settings.py?

    – Will Keeling
    Jan 22 at 19:59






  • 1





    May be related to this: stackoverflow.com/questions/43758492/… Exceptions are silenced in include tags when DEBUG is False.

    – Will Keeling
    Jan 23 at 9:07











  • @WillKeeling You right! in the template OPTIONS dictionary debug was not set to true. I changed And it working now. thanks.

    – SirSaleh
    Jan 23 at 12:54











  • @WillKeeling It will be appreciated if you add your answer. So I can accept and vote-up. thanks.

    – SirSaleh
    Jan 23 at 13:06






  • 1





    answer added - thanks!

    – Will Keeling
    Jan 23 at 13:23
















1















I have an issue with Django tests client.
Let for the home path I have this template (home.html):



<html>
<body>
{% include 'example.html' %}
</body>
</html>


and in example.html I have error:



<div>
{% non_registered_tag arg1 arg2 %}
</div>


I wrote a test for accessibility to a Django URL.



class HomePageAccess(TestCase):
def test_home_page(self):
client = Client()
response = client.get(reverse_lazy('home'))
self.assertEqual(response.status_code, 200)


This code fails successfully if there be an error in home.html, But if there be an error in example.html which is included in home.html Test will pass even though we expect to fail because I included it in home.html and in the browser I encounter an error (status code 500) while this not happens in test client.



Is it normal? I'm using Django 2.0.2.
Any help will be appreciated










share|improve this question




















  • 1





    In your settings.py do you have the debug option set in the OPTIONS dictionary of the TEMPLATES setting? And also what is the value of the overall DEBUG setting in settings.py?

    – Will Keeling
    Jan 22 at 19:59






  • 1





    May be related to this: stackoverflow.com/questions/43758492/… Exceptions are silenced in include tags when DEBUG is False.

    – Will Keeling
    Jan 23 at 9:07











  • @WillKeeling You right! in the template OPTIONS dictionary debug was not set to true. I changed And it working now. thanks.

    – SirSaleh
    Jan 23 at 12:54











  • @WillKeeling It will be appreciated if you add your answer. So I can accept and vote-up. thanks.

    – SirSaleh
    Jan 23 at 13:06






  • 1





    answer added - thanks!

    – Will Keeling
    Jan 23 at 13:23














1












1








1


1






I have an issue with Django tests client.
Let for the home path I have this template (home.html):



<html>
<body>
{% include 'example.html' %}
</body>
</html>


and in example.html I have error:



<div>
{% non_registered_tag arg1 arg2 %}
</div>


I wrote a test for accessibility to a Django URL.



class HomePageAccess(TestCase):
def test_home_page(self):
client = Client()
response = client.get(reverse_lazy('home'))
self.assertEqual(response.status_code, 200)


This code fails successfully if there be an error in home.html, But if there be an error in example.html which is included in home.html Test will pass even though we expect to fail because I included it in home.html and in the browser I encounter an error (status code 500) while this not happens in test client.



Is it normal? I'm using Django 2.0.2.
Any help will be appreciated










share|improve this question
















I have an issue with Django tests client.
Let for the home path I have this template (home.html):



<html>
<body>
{% include 'example.html' %}
</body>
</html>


and in example.html I have error:



<div>
{% non_registered_tag arg1 arg2 %}
</div>


I wrote a test for accessibility to a Django URL.



class HomePageAccess(TestCase):
def test_home_page(self):
client = Client()
response = client.get(reverse_lazy('home'))
self.assertEqual(response.status_code, 200)


This code fails successfully if there be an error in home.html, But if there be an error in example.html which is included in home.html Test will pass even though we expect to fail because I included it in home.html and in the browser I encounter an error (status code 500) while this not happens in test client.



Is it normal? I'm using Django 2.0.2.
Any help will be appreciated







django testing django-testing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 22 at 11:35









Javad

312




312










asked Jan 19 at 14:14









SirSalehSirSaleh

55921125




55921125








  • 1





    In your settings.py do you have the debug option set in the OPTIONS dictionary of the TEMPLATES setting? And also what is the value of the overall DEBUG setting in settings.py?

    – Will Keeling
    Jan 22 at 19:59






  • 1





    May be related to this: stackoverflow.com/questions/43758492/… Exceptions are silenced in include tags when DEBUG is False.

    – Will Keeling
    Jan 23 at 9:07











  • @WillKeeling You right! in the template OPTIONS dictionary debug was not set to true. I changed And it working now. thanks.

    – SirSaleh
    Jan 23 at 12:54











  • @WillKeeling It will be appreciated if you add your answer. So I can accept and vote-up. thanks.

    – SirSaleh
    Jan 23 at 13:06






  • 1





    answer added - thanks!

    – Will Keeling
    Jan 23 at 13:23














  • 1





    In your settings.py do you have the debug option set in the OPTIONS dictionary of the TEMPLATES setting? And also what is the value of the overall DEBUG setting in settings.py?

    – Will Keeling
    Jan 22 at 19:59






  • 1





    May be related to this: stackoverflow.com/questions/43758492/… Exceptions are silenced in include tags when DEBUG is False.

    – Will Keeling
    Jan 23 at 9:07











  • @WillKeeling You right! in the template OPTIONS dictionary debug was not set to true. I changed And it working now. thanks.

    – SirSaleh
    Jan 23 at 12:54











  • @WillKeeling It will be appreciated if you add your answer. So I can accept and vote-up. thanks.

    – SirSaleh
    Jan 23 at 13:06






  • 1





    answer added - thanks!

    – Will Keeling
    Jan 23 at 13:23








1




1





In your settings.py do you have the debug option set in the OPTIONS dictionary of the TEMPLATES setting? And also what is the value of the overall DEBUG setting in settings.py?

– Will Keeling
Jan 22 at 19:59





In your settings.py do you have the debug option set in the OPTIONS dictionary of the TEMPLATES setting? And also what is the value of the overall DEBUG setting in settings.py?

– Will Keeling
Jan 22 at 19:59




1




1





May be related to this: stackoverflow.com/questions/43758492/… Exceptions are silenced in include tags when DEBUG is False.

– Will Keeling
Jan 23 at 9:07





May be related to this: stackoverflow.com/questions/43758492/… Exceptions are silenced in include tags when DEBUG is False.

– Will Keeling
Jan 23 at 9:07













@WillKeeling You right! in the template OPTIONS dictionary debug was not set to true. I changed And it working now. thanks.

– SirSaleh
Jan 23 at 12:54





@WillKeeling You right! in the template OPTIONS dictionary debug was not set to true. I changed And it working now. thanks.

– SirSaleh
Jan 23 at 12:54













@WillKeeling It will be appreciated if you add your answer. So I can accept and vote-up. thanks.

– SirSaleh
Jan 23 at 13:06





@WillKeeling It will be appreciated if you add your answer. So I can accept and vote-up. thanks.

– SirSaleh
Jan 23 at 13:06




1




1





answer added - thanks!

– Will Keeling
Jan 23 at 13:23





answer added - thanks!

– Will Keeling
Jan 23 at 13:23












1 Answer
1






active

oldest

votes


















1














I suspect what's happening here is that you have the debug option set to False in the OPTIONS section in the TEMPLATES setting, or you have omitted it entirely (in which case it assumes the value of the overall DEBUG setting).



Explicitly setting debug to True should expose the error and your test should fail as expected.



TEMPLATES = [
{
...
'OPTIONS': {
'debug': True,
},
},
]


More information on the debug setting can be found in the template section of the Django docs here.






share|improve this answer


























  • Thanks, Will :)

    – SirSaleh
    Jan 23 at 13:30











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54267979%2fdjango-test-client-ignores-include-terms-in-django-template%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














I suspect what's happening here is that you have the debug option set to False in the OPTIONS section in the TEMPLATES setting, or you have omitted it entirely (in which case it assumes the value of the overall DEBUG setting).



Explicitly setting debug to True should expose the error and your test should fail as expected.



TEMPLATES = [
{
...
'OPTIONS': {
'debug': True,
},
},
]


More information on the debug setting can be found in the template section of the Django docs here.






share|improve this answer


























  • Thanks, Will :)

    – SirSaleh
    Jan 23 at 13:30
















1














I suspect what's happening here is that you have the debug option set to False in the OPTIONS section in the TEMPLATES setting, or you have omitted it entirely (in which case it assumes the value of the overall DEBUG setting).



Explicitly setting debug to True should expose the error and your test should fail as expected.



TEMPLATES = [
{
...
'OPTIONS': {
'debug': True,
},
},
]


More information on the debug setting can be found in the template section of the Django docs here.






share|improve this answer


























  • Thanks, Will :)

    – SirSaleh
    Jan 23 at 13:30














1












1








1







I suspect what's happening here is that you have the debug option set to False in the OPTIONS section in the TEMPLATES setting, or you have omitted it entirely (in which case it assumes the value of the overall DEBUG setting).



Explicitly setting debug to True should expose the error and your test should fail as expected.



TEMPLATES = [
{
...
'OPTIONS': {
'debug': True,
},
},
]


More information on the debug setting can be found in the template section of the Django docs here.






share|improve this answer















I suspect what's happening here is that you have the debug option set to False in the OPTIONS section in the TEMPLATES setting, or you have omitted it entirely (in which case it assumes the value of the overall DEBUG setting).



Explicitly setting debug to True should expose the error and your test should fail as expected.



TEMPLATES = [
{
...
'OPTIONS': {
'debug': True,
},
},
]


More information on the debug setting can be found in the template section of the Django docs here.







share|improve this answer














share|improve this answer



share|improve this answer








edited Jan 23 at 13:23

























answered Jan 22 at 17:58









Will KeelingWill Keeling

11.7k22434




11.7k22434













  • Thanks, Will :)

    – SirSaleh
    Jan 23 at 13:30



















  • Thanks, Will :)

    – SirSaleh
    Jan 23 at 13:30

















Thanks, Will :)

– SirSaleh
Jan 23 at 13:30





Thanks, Will :)

– SirSaleh
Jan 23 at 13:30


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54267979%2fdjango-test-client-ignores-include-terms-in-django-template%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Homophylophilia

Updating UILabel text programmatically using a function

Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage