#33925: Testing tools Management Commands example fails
-----------------------------------------+------------------------
               Reporter:  Eido95         |          Owner:  nobody
                   Type:  Bug            |         Status:  new
              Component:  Documentation  |        Version:  4.0
               Severity:  Normal         |       Keywords:
           Triage Stage:  Unreviewed     |      Has patch:  0
    Needs documentation:  0              |    Needs tests:  0
Patch needs improvement:  0              |  Easy pickings:  0
                  UI/UX:  0              |
-----------------------------------------+------------------------
 I added the test code in the
 [https://docs.djangoproject.com/en/4.0/topics/testing/tools/#management-
 commands following link], into my Django 4.0 project `tests.py`:
 {{{
 from io import StringIO
 from django.core.management import call_command
 from django.test import TestCase

 class ClosepollTest(TestCase):
     def test_command_output(self):
         out = StringIO()
         call_command('closepoll', stdout=out)
         self.assertIn('Expected output', out.getvalue())
 }}}
 The code fails with the following exception:


 {{{
 eido@:django-4.0-playground$ python mysite/manage.py test polls
 Found 11 test(s).
 Creating test database for alias 'default'...
 System check identified no issues (0 silenced).
 E..........
 ======================================================================
 ERROR: test_command_output (polls.tests.ClosepollTest)
 ----------------------------------------------------------------------
 Traceback (most recent call last):
   File
 "~/development/repositories/django-4.0-playground/mysite/polls/tests.py",
 line 145, in test_command_output
     call_command('closepoll', stdout=out)
   File "~/.local/share/virtualenvs/django-4.0-playground-
 KQUU8nfg/lib/python3.8/site-packages/django/core/management/__init__.py",
 line 176, in call_command
     defaults = parser.parse_args(args=parse_args)
   File "~/.local/share/virtualenvs/django-4.0-playground-
 KQUU8nfg/lib/python3.8/site-packages/django/core/management/base.py", line
 66, in parse_args
     return super().parse_args(args, namespace)
   File "/usr/lib/python3.8/argparse.py", line 1780, in parse_args
     args, argv = self.parse_known_args(args, namespace)
   File "/usr/lib/python3.8/argparse.py", line 1812, in parse_known_args
     namespace, args = self._parse_known_args(args, namespace)
   File "/usr/lib/python3.8/argparse.py", line 2046, in _parse_known_args
     self.error(_('the following arguments are required: %s') %
   File "~/.local/share/virtualenvs/django-4.0-playground-
 KQUU8nfg/lib/python3.8/site-packages/django/core/management/base.py", line
 72, in error
     raise CommandError("Error: %s" % message)
 django.core.management.base.CommandError: Error: the following arguments
 are required: poll_ids

 ----------------------------------------------------------------------
 Ran 11 tests in 0.024s

 FAILED (errors=1)
 Destroying test database for alias 'default'...
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33925>
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070182a041f628-040c66b5-bade-435f-8222-179d39a23273-000000%40eu-central-1.amazonses.com.

Reply via email to