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.
* 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>
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>