Welcome to the Treehouse Community
Looking to learn something new?
Oleksiy Ovdienko447 Points
Is it good if test in this video doesn't passes, crashes with error on self.assertLess course.created_at not less than
Is it good if test in this video doesn't passes, crashes with error on self.assertLess course.created_at not less than now ?
No... if you followed the videos up until now and added the code as Kenneth did, that test should pass without an issue.
If you're worried that the times you're comparing are too close together, you could add a delay by using time.sleep():
from django.test import TestCase from django.utils import timezone import time # don't forget to import the module first from .models import Course class CourseModelTests(TestCase): def test_course_creation(self): course = Course.objects.create( title="Python Regular Expressions", description="Learn to write regular expressions in Python" ) time.sleep(1) # sleep/delay for one second now = timezone.now() self.assertLess(course.created_at, now)
Jeff MudayTreehouse Moderator 27,510 Points
Some test environments on your local host will be so fast that when you run now it will be in the same millisecond as the creation step. This happens on my home computer.
Your test is fine.