Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7565261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:06:32+00:00 2026-05-30T14:06:32+00:00

I am using unittest.TestCase to write test cases for my django app (which is

  • 0

I am using unittest.TestCase to write test cases for my django app (which is essentially the same unittest.TestCase from python). Whenever a test method fails, I get the explanation of it in the format below. Is there a way that I can add custom/debug messages to the output of failed test method?

======================================================================
FAIL: test_bad_votes (polls.tests.views.PollsViewsTestCase)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/colinh/Development/tutorials/guide-to-testing-in-django/polls/tests/views.py", line 66, in test_bad_votes
    self.assertEqual(resp.context['form']['choice'].errors, [u'This field is required.'])
AssertionError: [] != [u'This field is required.']
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T14:06:33+00:00Added an answer on May 30, 2026 at 2:06 pm

    In general, you want to inherit from django’s unittest class TestCase, which you can get by importing from django.test. That said, you can pass a msg argument to whatever you’re trying to evaluate, containing the failure message.

    Here’s an example from Humanize:

    class HumanizeTests(TestCase):
    
        def humanize_tester(self, test_list, result_list, method):
            # Using max below ensures we go through both lists
            # However, if the lists are not equal length, this raises an exception
            for test_content, result in zip(test_list, result_list):
                t = Template('{%% load humanize %%}{{ test_content|%s }}' % method)
                rendered = t.render(Context(locals())).strip()
                self.assertEqual(rendered, escape(result),
                             msg="%s test failed, produced '%s', should've produced '%s'" %     (method, rendered, result))
    

    Obviously, yours doesn’t need to look like the above, but you can see the msg argument in action.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using the Google App Engine testbed framework to write test cases with
I am trying to do a simple test in Python using ' unittest ',
I used unittest and nose for unit-testing in Python but now I'm using py.test.
I am using python unit test module. I am wondering is there anyway to
Hello I have test's using unittest. I have a test suite and I am
Context : python 2.6.5 environment I am using unittest.defaultTestLoader.loadTestsFromModule(module) to load tests. However, when
I am using Python's unittest with simple code like so: suite = unittest.TestSuite() suite.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(module1))
The Goal: Access / Write to the same temp files when using a common
I recorded an action using the Selenium IDE and used the File->Export Test Cases
I have the following code (as an example) in a unittest TestCase def test(self):

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.