Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/howto/custom-management-commands.txt
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,12 @@ non-uniform locales, so you might need to:
differences when locales are changed and evaluate its impact on
predictable behavior of your command.

Testing
=======

Information on how to test custom management commands can be found in the
:ref:`testing docs <topics-testing-management-commands>`.

Command objects
===============

Expand Down
21 changes: 21 additions & 0 deletions docs/topics/testing/tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1623,6 +1623,27 @@ manually, assign the empty list to ``mail.outbox``::
# Empty the test outbox
mail.outbox = []

.. _topics-testing-management-commands:

Management Commands
-------------------

Management commands can be tested with the
:func:`~django.core.management.call_command` function. The output can be
redirected into a ``StringIO`` instance.

::

from django.test import TestCase
from django.core.management import call_command
from django.utils.six import StringIO

class ClosepollTest(TestCase):
def test_command(self):
out = StringIO()
call_command('closepoll', stdout=out)
self.assertIn('Expected output', out.getvalue())

.. _skipping-tests:

Skipping tests
Expand Down