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

  • SEARCH
  • Home
  • 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 8775649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:51:28+00:00 2026-06-13T18:51:28+00:00

So I’m learning how to practice TDD in Django and I’m having some minor

  • 0

So I’m learning how to practice TDD in Django and I’m having some minor trouble. I created a custom user object that links to authenticated system users in a one to one relationship. I have the following test, which exercises part of my custom user class:

def test_creating_a_user_with_attributes(self):
    myuser = Myuser.objects.create_user('Gary', email='me@email.com')
    current_time = now()
    myuser.birthday = current_time
    myuser.save()
    first_user = Myuser.objects.all()[0]
    self.assertEqual(first_user.birthday, current_time, 'first_user.birthday should be equal to the current_time')

The problem is that my test was failing and I couldn’t immediately see why. The assert failure reported the message I had supplied and I was confused because I was certain that the birthday was set to the value of now. I ended up having to refactor my assert to make the failing value clear.

    self.assertEqual(first_user.birthday, current_time,
        'first_user.birthday ' + str(first_user.birthday) + ' should equal ' + str(current_time))

This revealed that the birthday was a date field and not a datetime field. My question is wether there exists some alternate form of assert that dumps the expected and actual values as part of the failure message or if I am somehow misusing or misunderstanding the API?

  • 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-06-13T18:51:30+00:00Added an answer on June 13, 2026 at 6:51 pm

    Django doesn’t implement assertEqual, it simply uses Python’s unittest module for that one.

    What you need is to set the longMessage attribute to True for your test case class, like so:

    class VerboseTestCase(TestCase):
        longMessage = True
    
        def test_creating_a_user_with_attributes(self):
            myuser = Myuser.objects.create_user('Gary', email='me@email.com')
            current_time = now()
            myuser.birthday = current_time
            myuser.save()
            first_user = Myuser.objects.all()[0]
            self.assertEqual(first_user.birthday, current_time, 'first_user.birthday should be equal to the current_time')
    

    Which will output something like this if the test fails:

    AssertionError: <datetime 1> != <datetime 2> : first_user.birthday should be equal to the current_time
    

    This is explained in Python’s unittest docs.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into

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.