From 276332d85c76a4de9fc1cb4bcb2f1636c0322414 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Sat, 15 Nov 2014 12:13:05 +0100 Subject: [PATCH] [1.6.x] Fixed #23543 -- Added docs on testing management command output. Backport of cdee8659763ee7044c1507bcd2202581b1744f0b from master --- docs/howto/custom-management-commands.txt | 6 ++++++ docs/topics/testing/tools.txt | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/docs/howto/custom-management-commands.txt b/docs/howto/custom-management-commands.txt index c5fc7ca06f..c0ccb5faeb 100644 --- a/docs/howto/custom-management-commands.txt +++ b/docs/howto/custom-management-commands.txt @@ -178,6 +178,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 `. + Command objects =============== diff --git a/docs/topics/testing/tools.txt b/docs/topics/testing/tools.txt index 41fcdf4a85..7d9b92615a 100644 --- a/docs/topics/testing/tools.txt +++ b/docs/topics/testing/tools.txt @@ -1481,6 +1481,25 @@ 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.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