Ticket #19665: 19665-1.diff

File 19665-1.diff, 2.3 KB (added by Claude Paroz, 12 years ago)
  • django/core/management/base.py

    diff --git a/django/core/management/base.py b/django/core/management/base.py
    index 895753e..fb3f22c 100644
    a b class BaseCommand(object):  
    221221        try:
    222222            self.execute(*args, **options.__dict__)
    223223        except Exception as e:
     224            stderr = getattr(self, 'stderr', OutputWrapper(sys.stderr, self.style.ERROR))
    224225            if options.traceback:
    225                 self.stderr.write(traceback.format_exc())
    226             self.stderr.write('%s: %s' % (e.__class__.__name__, e))
     226                stderr.write(traceback.format_exc())
     227            stderr.write('%s: %s' % (e.__class__.__name__, e))
    227228            sys.exit(1)
    228229
    229230    def execute(self, *args, **options):
  • tests/regressiontests/admin_scripts/tests.py

    diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
    index df2326e..8be687a 100644
    a b import codecs  
    1616
    1717from django import conf, bin, get_version
    1818from django.conf import settings
     19from django.core.management import BaseCommand
    1920from django.db import connection
    2021from django.test.simple import DjangoTestSuiteRunner
    2122from django.utils import unittest
    2223from django.utils.encoding import force_str, force_text
    2324from django.utils._os import upath
     25from django.utils.six import StringIO
    2426from django.test import LiveServerTestCase
    2527
    2628test_dir = os.path.dirname(os.path.dirname(upath(__file__)))
    class CommandTypes(AdminScriptTestCase):  
    12791281        self.assertNoOutput(err)
    12801282        self.assertOutput(out, "EXECUTE:BaseCommand labels=('testlabel',), options=[('option_a', 'x'), ('option_b', 'y'), ('option_c', '3'), ('pythonpath', None), ('settings', None), ('traceback', None), ('verbosity', '1')]")
    12811283
     1284    def test_base_run_from_argv(self):
     1285        "Test run_from_argv properly terminates even with custom execute() (#19665)"
     1286        command = BaseCommand()
     1287        command.execute = lambda *args: args
     1288
     1289        old_stderr = sys.stderr
     1290        sys.stderr = StringIO()
     1291        try:
     1292            with self.assertRaises(SystemExit):
     1293                command.run_from_argv(['', ''])
     1294        finally:
     1295            sys.stderr = old_stderr
     1296
    12821297    def test_noargs(self):
    12831298        "NoArg Commands can be executed"
    12841299        args = ['noargs_command']
Back to Top