import cStrinIO import sys from django.test import TestCase class MyCommandTestCase(TestCase): def test_mycommand_failure(self): old_stderr = sys.stderr sys.stderr = cStringIO.StringIO() self.assertRaises(BaseException, management.call_command, 'mycommand') self.assertTrue('Error: Some error condition here' in sys.stderr.getvalue()) sys.stderr = old_stderr