'Exception raised in a command should raise CommandError with
call_command, but SystemExit when run from command line'

def test_system_exit(self):

    with self.assertRaises(CommandError):
        management.call_command('dance', example='raise')
    dance.Command.requires_system_checks = False
    try:
        with captured_stderr() as stderr:
            with self.assertRaises(SystemExit):
                management.ManagementUtility(['manage.py', 'dance', '--example=raise']).execute()
    finally:
        dance.Command.requires_system_checks = True
    self.assertIn('CommandError', stderr.getvalue())
