diff --git a/django/core/management/base.py b/django/core/management/base.py
index 895753e..fb3f22c 100644
a
|
b
|
class BaseCommand(object):
|
221 | 221 | try: |
222 | 222 | self.execute(*args, **options.__dict__) |
223 | 223 | except Exception as e: |
| 224 | stderr = getattr(self, 'stderr', OutputWrapper(sys.stderr, self.style.ERROR)) |
224 | 225 | 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)) |
227 | 228 | sys.exit(1) |
228 | 229 | |
229 | 230 | def execute(self, *args, **options): |
diff --git a/tests/regressiontests/admin_scripts/tests.py b/tests/regressiontests/admin_scripts/tests.py
index df2326e..8be687a 100644
a
|
b
|
import codecs
|
16 | 16 | |
17 | 17 | from django import conf, bin, get_version |
18 | 18 | from django.conf import settings |
| 19 | from django.core.management import BaseCommand |
19 | 20 | from django.db import connection |
20 | 21 | from django.test.simple import DjangoTestSuiteRunner |
21 | 22 | from django.utils import unittest |
22 | 23 | from django.utils.encoding import force_str, force_text |
23 | 24 | from django.utils._os import upath |
| 25 | from django.utils.six import StringIO |
24 | 26 | from django.test import LiveServerTestCase |
25 | 27 | |
26 | 28 | test_dir = os.path.dirname(os.path.dirname(upath(__file__))) |
… |
… |
class CommandTypes(AdminScriptTestCase):
|
1279 | 1281 | self.assertNoOutput(err) |
1280 | 1282 | 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')]") |
1281 | 1283 | |
| 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 | |
1282 | 1297 | def test_noargs(self): |
1283 | 1298 | "NoArg Commands can be executed" |
1284 | 1299 | args = ['noargs_command'] |