diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/admin_scripts/tests.py | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index 62c6f485aa..a82f5be5ed 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -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): |
