Skip to content

Commit

Permalink
merge branch 'master' of github.com:django-extensions/django-extensions
Browse files Browse the repository at this point in the history
* 'master' of github.com:django-extensions/django-extensions:
  fix shell_plus --command globals / locals error
  • Loading branch information
trbs committed Apr 5, 2021
2 parents 29af891 + fe5f961 commit bf745e2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion django_extensions/management/commands/shell_plus.py
Expand Up @@ -575,7 +575,7 @@ def try_runner(get_runner):

if options['command']:
imported_objects = self.get_imported_objects(options)
exec(options['command'], {}, imported_objects)
exec(options['command'], imported_objects)
return None

runner()
14 changes: 12 additions & 2 deletions tests/management/commands/shell_plus_tests/test_shell_plus.py
Expand Up @@ -4,18 +4,28 @@
import pytest
import inspect

from io import StringIO
from textwrap import dedent
from django.core.management import call_command
from django.db.models import Model
from django.test import override_settings

from django_extensions.management.commands import shell_plus


def test_shell_plus_command(capsys):
script = dedent('''\
def _fn(x): return x * 2
print([_fn(i) for i in range(10)])
''')
call_command("shell_plus", "--command=" + script)
out, err = capsys.readouterr()

assert out.rstrip().endswith(repr([i * 2 for i in range(10)]))


@pytest.mark.django_db()
@override_settings(SHELL_PLUS_SQLPARSE_ENABLED=False, SHELL_PLUS_PYGMENTS_ENABLED=False)
def test_shell_plus_print_sql(capsys):
out = StringIO()
try:
from django.db import connection
from django.db.backends import utils
Expand Down

0 comments on commit bf745e2

Please sign in to comment.