From 13d60298ea2a07242dc3952a9dfcd9c8857bf1f9 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Thu, 16 Jun 2016 11:19:18 -0700 Subject: [1.10.x] Fixed #26747 -- Used more specific assertions in the Django test suite. Backport of 4f336f66523001b009ab038b10848508fd208b3b from master --- docs/intro/tutorial05.txt | 10 +++++----- docs/topics/testing/overview.txt | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'docs') diff --git a/docs/intro/tutorial05.txt b/docs/intro/tutorial05.txt index bfb43358e6..f88f6686bd 100644 --- a/docs/intro/tutorial05.txt +++ b/docs/intro/tutorial05.txt @@ -180,7 +180,7 @@ Put the following in the ``tests.py`` file in the ``polls`` application: """ time = timezone.now() + datetime.timedelta(days=30) future_question = Question(pub_date=time) - self.assertEqual(future_question.was_published_recently(), False) + self.assertIs(future_question.was_published_recently(), False) What we have done here is created a :class:`django.test.TestCase` subclass with a method that creates a ``Question`` instance with a ``pub_date`` in the @@ -203,8 +203,8 @@ and you'll see something like:: ---------------------------------------------------------------------- Traceback (most recent call last): File "/path/to/mysite/polls/tests.py", line 16, in test_was_published_recently_with_future_question - self.assertEqual(future_question.was_published_recently(), False) - AssertionError: True != False + self.assertIs(future_question.was_published_recently(), False) + AssertionError: True is not False ---------------------------------------------------------------------- Ran 1 test in 0.001s @@ -285,7 +285,7 @@ more comprehensively: """ time = timezone.now() - datetime.timedelta(days=30) old_question = Question(pub_date=time) - self.assertEqual(old_question.was_published_recently(), False) + self.assertIs(old_question.was_published_recently(), False) def test_was_published_recently_with_recent_question(self): """ @@ -294,7 +294,7 @@ more comprehensively: """ time = timezone.now() - datetime.timedelta(hours=1) recent_question = Question(pub_date=time) - self.assertEqual(recent_question.was_published_recently(), True) + self.assertIs(recent_question.was_published_recently(), True) And now we have three tests that confirm that ``Question.was_published_recently()`` returns sensible values for past, recent, and future questions. diff --git a/docs/topics/testing/overview.txt b/docs/topics/testing/overview.txt index eca477bdd9..aa6a7af191 100644 --- a/docs/topics/testing/overview.txt +++ b/docs/topics/testing/overview.txt @@ -304,8 +304,8 @@ failed:: ---------------------------------------------------------------------- Traceback (most recent call last): File "/dev/mysite/polls/tests.py", line 16, in test_was_published_recently_with_future_poll - self.assertEqual(future_poll.was_published_recently(), False) - AssertionError: True != False + self.assertIs(future_poll.was_published_recently(), False) + AssertionError: True is not False ---------------------------------------------------------------------- Ran 1 test in 0.003s -- cgit v1.3