Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Basics Test Time View Tests

Too Fast! Python's so fast that my test_course_creation test keeps failing...

In testing the Course model using the code in the video, I get an error message like the one below. I guess, while all of the 5 tests take a total of 31 milliseconds to complete, the speed with which Python goes from creating a Course instance to the "now" variable is less than a millisecond... so that the "self.assertLess(course.created_at, now)" produces the following error:

AssertionError: datetime.datetime(2017, 8, 19, 4, 36, 15, 156198, tzinfo=<UTC>) not less than datetime.datetime(2017, 8, 19, 4, 36, 15, 156198, tzinfo=<UTC>)

----------------------------------------------------------------------
Ran 5 tests in 0.031s

Both datetime objects have the same time... even to the millisecond.

1 Answer

I changed the "assertLess" to "assertLessEqual" and the test passed.
Just fyi in case others have this same issue. Thanks! D.