Testing for failure in management commands

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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

More like this

  1. Django and Twill by spookylukey 5 years, 1 month ago
  2. Forcing unit test runner to abort after failed test by simonbun 6 years ago
  3. Add example contact with BaseCommand by magik_cypress 9 months, 1 week ago
  4. Add example content with BaseCommand by magik_cypress 9 months, 1 week ago
  5. Monitoring django-sphinx for Nagios by johnnoone 4 years, 1 month ago

Comments

(Forgotten your password?)