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. Forcing unit test runner to abort after failed test by simonbun 4 years, 8 months ago
  2. Variable._resolve_lookup monkeypatch by showell 2 years, 2 months ago
  3. Django and Twill by spookylukey 3 years, 10 months ago
  4. "Zoom in" on rendered HTML that the test client returns by peterbe 2 years, 9 months ago
  5. Stop tests at the first failure by akaihola 4 years, 1 month ago

Comments

(Forgotten your password?)