[Django] #33925: Testing tools Management Commands example fails

6 views
Skip to first unread message

Django

unread,
Aug 15, 2022, 2:47:37 AM8/15/22
to django-...@googlegroups.com
#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.

Django

unread,
Aug 15, 2022, 3:08:48 AM8/15/22
to django-...@googlegroups.com
#33925: Testing tools Management Commands example fails
-------------------------------+--------------------------------------
Reporter: Eido95 | Owner: nobody
Type: Bug | Status: closed
Component: Documentation | Version: 4.0
Severity: Normal | Resolution: invalid

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => invalid


Comment:

Thanks for this ticket, however this is only a stub test and doesn't
contain a source of `closepoll` command, it also doesn't refer to the
implementation from [https://docs.djangoproject.com/en/stable/howto
/custom-management-commands/#module-django.core.management How-to].

This section is intended to show that the `call_command()` function is
useful for testing management commands. We shouldn't complicate it with
the ORM calls and extra arguments.

--
Ticket URL: <https://code.djangoproject.com/ticket/33925#comment:1>

Django

unread,
Aug 28, 2022, 3:21:50 AM8/28/22
to django-...@googlegroups.com
#33925: Testing tools Management Commands example fails
-------------------------------+--------------------------------------
Reporter: Eido Askayo | Owner: nobody

Type: Bug | Status: closed
Component: Documentation | Version: 4.0
Severity: Normal | Resolution: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Eido Askayo):

Replying to [comment:1 Mariusz Felisiak]:


> Thanks for this ticket, however this is only a stub test and doesn't
contain a source of `closepoll` command, it also doesn't refer to the
implementation from [https://docs.djangoproject.com/en/stable/howto
/custom-management-commands/#module-django.core.management How-to].
>
> This section is intended to show that the `call_command()` function is
useful for testing management commands. We shouldn't complicate it with
the ORM calls and extra arguments.

Thank you for your consideration.

--
Ticket URL: <https://code.djangoproject.com/ticket/33925#comment:2>

Reply all
Reply to author
Forward
0 new messages