Skip to content

Commit 276332d

Browse files
dbrgntimgraham
authored andcommitted
[1.6.x] Fixed #23543 -- Added docs on testing management command output.
Backport of cdee865 from master
1 parent 1fa2e7a commit 276332d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

docs/howto/custom-management-commands.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,12 @@ non-uniform locales, so you might need to:
178178
differences when locales are changed and evaluate its impact on
179179
predictable behavior of your command.
180180

181+
Testing
182+
=======
183+
184+
Information on how to test custom management commands can be found in the
185+
:ref:`testing docs <topics-testing-management-commands>`.
186+
181187
Command objects
182188
===============
183189

docs/topics/testing/tools.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,25 @@ manually, assign the empty list to ``mail.outbox``::
14811481
# Empty the test outbox
14821482
mail.outbox = []
14831483

1484+
.. _topics-testing-management-commands:
1485+
1486+
Management Commands
1487+
-------------------
1488+
1489+
Management commands can be tested with the
1490+
:func:`~django.core.management.call_command` function. The output can be
1491+
redirected into a ``StringIO`` instance::
1492+
1493+
from django.core.management import call_command
1494+
from django.test import TestCase
1495+
from django.utils.six import StringIO
1496+
1497+
class ClosepollTest(TestCase):
1498+
def test_command_output(self):
1499+
out = StringIO()
1500+
call_command('closepoll', stdout=out)
1501+
self.assertIn('Expected output', out.getvalue())
1502+
14841503
.. _skipping-tests:
14851504

14861505
Skipping tests

0 commit comments

Comments
 (0)