'Test run_from_argv properly terminates even with custom execute() (#19665)
Also test proper traceback display.'

def test_base_run_from_argv(self):

    err = StringIO()
    command = BaseCommand(stderr=err)
    def raise_command_error(*args, **kwargs):
        raise CommandError('Custom    error')
    command.execute = (lambda args: args)
    with self.assertRaises(TypeError):
        command.run_from_argv(['', ''])
    command.execute = raise_command_error
    err.truncate(0)
    with self.assertRaises(SystemExit):
        command.run_from_argv(['', ''])
    err_message = err.getvalue()
    self.assertNotIn('Traceback', err_message)
    self.assertIn('CommandError', err_message)
    err.truncate(0)
    with self.assertRaises(CommandError):
        command.run_from_argv(['', '', '--traceback'])
