Search code examples
djangodjango-testingdjango-manage.pydjango-tests

How to handle CommandError exceptions in Django tests


I'm creating a Management Command in which I raise a CommandError exception when something goes wrong.

One of my test cases executes the command in a way that it will raise the exception so the result of the test is Error.

How can I make it pass?


Solution

  • If your expected behaviour is exception, you can use the assertRaises, look here: https://docs.python.org/2/library/unittest.html#unittest.TestCase.assertRaises