My query is related to the part 5 of the Django Tutorial
Let me share the part of the code (from polls/tests.py) related to my query;
def create_question(question_text, days):
#...
time = timezone.now() + datetime.timedelta(days=days)
return Question.objects.create(question_text=question_text, pub_date=time)
class QuestionIndexViewTests(TestCase):
# ...
def test_future_question_and_past_question(self):
"""
Even if both past and future questions exist, only past questions
are displayed.
"""
question = create_question(question_text="Past question.", days=-30)
create_question(question_text="Future question.", days=30)
response = self.client.get(reverse("polls:index"))
self.assertQuerySetEqual(
response.context["latest_question_list"],
[question],
)
#......
In the function test_future_question_and_past_question(),
observe the two statements;
question = create_question(question_text="Past question.", days=-30)
create_question(question_text="Future question.", days=30)
The first statement creates a past question and saves it in a variable named ‘question’. The second statement creates a future question but does not save it.
Is not this a syntax error as the method create_question() when called returns an instance of Question type which is not received by some variable like in the first statement?
Best Regards.