The reason why assertIs is used instead of assertFalse is that the latter actually tests for falsy values and can sometimes hide bugs.
For example, assertFalse(0) and assertFalse(None) will pass and assertTrue(42) will as well.
If you're testing a method that is supposed to return a boolean value you're better off using assertIs.
Cheers,
Simon
Le jeudi 25 octobre 2018 15:42:00 UTC-4, John Meyer a écrit :
tests.py in the tutorial gives this example:self.assertIs(future_question.was_published_recently (), False)This implies that assertIs tests equality of two booleans. The code works, but not for the right reason, as per the language documentation, the assertIs does not test equality but tests whether two object references point to the same object:assertIs(first, second, msg=None )assertIsNot(first, second, msg=None )
Test that first and second evaluate (or don't evaluate) to the same object.
New in version 3.1.This invites tests being written that are testing other kinds of equality and the results are not reliable. There are a few posts on StackOverflow indicating this confusion is causing confusion in the community. I want to update the tutorial to use assertEquals or assertTrue. I'm not in charge of the documentation so I'd settle for posting a bug request for this in the right place, if the point is valid.Thoughts?
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/58f6d409-98db-49c1-884b-6c631ece8023%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment