TestCase console closes automatically.

I don’t know how to keep the window open for readability. Or even if it is functioning correctly.

I think you’re going to need to provide a lot more detail here.

  • What operating system are you using?
  • What versions of Python and Django are involved?
  • How are you running your test case?
  • What is the test case you’re running?
  • Does this still occur on the most trivial test case?
  • Have you tried redirecting stdout & stderr to files to see what output may be generated?

I’m following the tutorial to familiarize myself with Django. So I’m on Writing your first Django app, part 5 | Django documentation | Django. And just the first test.

  • Windows 11 v22H2
    • Powershell v5.1.22621.1778
  • Django version 4.2.4
  • Python 3.11.4
  • .\manage.py test polls
    My understanding of Powershell is that you should be able to pipe the output to another file using |

Code:

import datetime

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

from .models import Question


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

Try it from the command prompt (cmd) instead of powershell.

Yeah, that worked. Thank you.
Also, I found adding "py " in front of the command fixed it as well:

Powershell
py .\manage.py test polls works runs in same window
.\manage.py test polls launches another window and auto closes (what I was initially trying)

cmd
py .\manage.py test polls works runs in same window
.\manage.py test polls works runs in same window