How can I fix error in part 5 when I try to ``` create shortcut function to create questions and new test class: ```

In my polls/tests.py file I am getting a warning saying create_question not defined. This baffles me because just a few lines above this error message I have created the function create_question(). Please help. From what I have learned from @KenWhitesell the problem could be a stray comma in my code. So where could the problem be??? In Visual Studio Coce the amber/yellow squiggly error/warning is on line 59. The warning says create_question not defined. Here is my code

import datetime

from django.test import TestCase
from django.utils import timezone
from django.urls import reverse

from .models import Question

# Create your tests here.


class QuestionModelTests(TestCase):
    def test_was_published_recently_with_future_question(self):
        ### was)published_recently() returns False for questions whose pub_dte is in the future ###
        time = timezone.now() + datetime.timedelta(days=30)
        future_question = Question(pub_dte=time)
        self.assertIs(future_question.was_published_recently(), False)

    def test_was_published_recently_with_old_question(self):
        ### was_published_recently() returns False 
        # for questions whose pub_dte is older thsn 1 day ###

        time = timezone.now() - datetime.timedelta(days=1,seconds=1)
        old_question = Question(pub_dte=time)
        self.assertIs(old_question.was_published_recently(), False)


    def test_was_published_recently_with_recent_question(self):
        ###  was_published_recently() returns True 
        # for questions whose pub_dte is within the last day ###

        time = timezone.now() - datetime.timedelta(hours=23, minutes=59, seconds=59)
        recent_question = Question(pub_dte=time)
        self.assertIs(recent_question.was_published_recently(), True)


    def create_question(question_text, days):

        """Create a question with the given 'question_text'
        and published the given number of 'days' 
        offset to now (negative or questions 
        published in the past, positive for questions
        that have yet to be published),"""
        time = timezone.now() + datetime.timedelta(days=days)
        return Question.objects.create(question_text=question_text, pub_dte=time)
    

    class QuestionIndexViewTests(TestCase):
        def test_no_question(self):
            """ If no questions exist, an appropriate message is displayed. """
            response = self.client.get(reverse("polls:index.html"))
            self.assertEqual(response.status_code, 200)
            self.assertContains(response, "No polls are available.")
            self.assertQuerySetEqual(response.context["latest_question_list"], [])

        def test_past_question(self):
            """ Questions with a pub_dte in the past are displayed
                on the index page."""
            question = create_question(question_text="Past question.", days=-30)
            response = self.client.get(reverse("polls:index"))
            self.assertQuerySetEqual(response.context["latest_question_list"], [question],)@
                

Please post your tests.py file here. It’s really tough trying to diagnose a problem like this without seeing the code. (The problem could be in any number of different places.)

I think I have posted the tests.py file. Only thing is I do not see the line numbers in the code I have posted. I am using VS code. The warning is on line 59

If this is an accurate posting of your code, then you have incorrect indentation in your code.

You show your create_question function as being indented (contained) in the QuestionModelTests class. This is not correct. That function should be at the outermost level.

Also, your QuestionIndexViewTests class is also indented incorrectly. That class should be at the outermost level.

Side note: Thank you for using the backticks on your post. Note that the lines of ``` must be lines by themselves and not part of any other line. (I fixed your post for you.)

Okay. Thanks. Let me go back to my code

Yep. @KenWhitesell, you are spot on correct. I change the indentation and the warning squiggly line disappeared. Thank you