[1.6.x] Fixed #23543 -- Added docs on testing management command output.

Backport of cdee8659763ee7044c1507bcd2202581b1744f0b from master
This commit is contained in:
Danilo Bargen 2014-11-15 12:13:05 +01:00 committed by Tim Graham
parent 1fa2e7aba1
commit 276332d85c
2 changed files with 25 additions and 0 deletions

View File

@ -178,6 +178,12 @@ non-uniform locales, so you might need to:
differences when locales are changed and evaluate its impact on differences when locales are changed and evaluate its impact on
predictable behavior of your command. 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 Command objects
=============== ===============

View File

@ -1481,6 +1481,25 @@ manually, assign the empty list to ``mail.outbox``::
# Empty the test outbox # Empty the test outbox
mail.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.core.management import call_command
from django.test import TestCase
from django.utils.six import StringIO
class ClosepollTest(TestCase):
def test_command_output(self):
out = StringIO()
call_command('closepoll', stdout=out)
self.assertIn('Expected output', out.getvalue())
.. _skipping-tests: .. _skipping-tests:
Skipping tests Skipping tests