#31476: Django Tutorial 5 - Testing create_question issue - Assetion Failure -------------------------------------+------------------------------------- Reporter: adavie1 | Owner: nobody Type: Bug | Status: new Component: | Version: 3.0 Documentation | Severity: Normal | Keywords: tutorial, testing Triage Stage: | Has patch: 0 Unreviewed | Needs documentation: 0 | Needs tests: 0 Patch needs improvement: 0 | Easy pickings: 0 UI/UX: 0 | -------------------------------------+------------------------------------- Firstly, thanks for a great tutorial! I'm really enjoying learning Django.
Secondly, the code in the Testing Tutorial (#6): {{{ create_question(question_text="Past question.", days=-30) }}} is redundant? This works as well: {{{ create_question("Past question.", -30) }}} My error is this: {{{ AssertionError: Lists differ: [] != ['<Question: Past question>'] Second list contains 1 additional elements. First extra element 0: '<Question: Past question>' - [] + ['<Question: Past question>'] }}} For future question, I'm getting this: {{{ AssertionError: Lists differ: ['<Question: Future question>'] != [] First list contains 1 additional elements. First extra element 0: '<Question: Future question>' - ['<Question: Future question>'] + [] }}} This is the code for test_past_question: {{{ def test_past_question(self): """ Questions with a published_date in the past. """ create_question('Past question', days=-30) resp = self.client.get(reverse('polls:index')) self.assertQuerysetEqual( resp.context['latest'], ['<Question: Past question>'] ) }}} and my create_question method: {{{ def create_question(text, days): """ Create a Question with text and days from now. -ve in the past, +ve in the future. """ time = timezone.now() - datetime.timedelta(days=days) q = Question.objects.create(question_text=text, published_date=time) # pr = "create_question(" + text + ", " + str(days) + ")" # print(pr, q) return q }}} I've been knocking my head over this for the last few days. Any help much appreciated. -- Ticket URL: <https://code.djangoproject.com/ticket/31476> Django <https://code.djangoproject.com/> The Web framework for perfectionists with deadlines. -- You received this message because you are subscribed to the Google Groups "Django updates" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-updates+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/050.d94c755a460535814d6eed34d8e083ba%40djangoproject.com.