mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #32177 -- Made execute_from_command_line() use program name from the argv argument.
This caused crash in environments where sys.argv[0] is incorrectly set to None.
This commit is contained in:
parent
0773837e15
commit
cc22693505
2 changed files with 22 additions and 2 deletions
|
@ -17,7 +17,7 @@ from unittest import mock
|
|||
from django import conf, get_version
|
||||
from django.conf import settings
|
||||
from django.core.management import (
|
||||
BaseCommand, CommandError, call_command, color,
|
||||
BaseCommand, CommandError, call_command, color, execute_from_command_line,
|
||||
)
|
||||
from django.core.management.commands.loaddata import Command as LoaddataCommand
|
||||
from django.core.management.commands.runserver import (
|
||||
|
@ -31,6 +31,7 @@ from django.db.migrations.recorder import MigrationRecorder
|
|||
from django.test import (
|
||||
LiveServerTestCase, SimpleTestCase, TestCase, override_settings,
|
||||
)
|
||||
from django.test.utils import captured_stderr, captured_stdout
|
||||
|
||||
custom_templates_dir = os.path.join(os.path.dirname(__file__), 'custom_templates')
|
||||
|
||||
|
@ -1867,6 +1868,20 @@ class ArgumentOrder(AdminScriptTestCase):
|
|||
)
|
||||
|
||||
|
||||
class ExecuteFromCommandLine(SimpleTestCase):
|
||||
def test_program_name_from_argv(self):
|
||||
"""
|
||||
Program name is computed from the execute_from_command_line()'s argv
|
||||
argument, not sys.argv.
|
||||
"""
|
||||
args = ['help', 'shell']
|
||||
with captured_stdout() as out, captured_stderr() as err:
|
||||
with mock.patch('sys.argv', [None] + args):
|
||||
execute_from_command_line(['django-admin'] + args)
|
||||
self.assertIn('usage: django-admin shell', out.getvalue())
|
||||
self.assertEqual(err.getvalue(), '')
|
||||
|
||||
|
||||
@override_settings(ROOT_URLCONF='admin_scripts.urls')
|
||||
class StartProject(LiveServerTestCase, AdminScriptTestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue