Skip to content

Conversation

nessita
Copy link
Contributor

@nessita nessita commented Jul 17, 2025

Trac ticket number

ticket-35680

Branch description

Following a5cd84a, I started getting this test failure when running the tests:

======================================================================
FAIL: test_message_with_stdout_no_installed_apps (shell.tests.ShellCommandAutoImportsTestCase.test_message_with_stdout_no_installed_apps) [<object object at 0x74bfb52cb140>] (verbosity=2)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/usr/lib/python3.13/unittest/case.py", line 58, in testPartExecutor
    yield
  File "/usr/lib/python3.13/unittest/case.py", line 556, in subTest
    yield
  File "/home/nessita/fellowship/django/tests/shell/tests.py", line 422, in test_message_with_stdout_no_installed_apps
    self.assertEqual(stdout.getvalue().strip(), expected)
    ^^^
  File "/usr/lib/python3.13/unittest/case.py", line 907, in assertEqual
    assertion_func(first, second, msg=msg)
    ^^^^^^^^^^^^^^^
  File "/usr/lib/python3.13/unittest/case.py", line 1273, in assertMultiLineEqual
    self.fail(self._formatMessage(msg, standardMsg))
    ^^^^^^^^^^^
  File "/usr/lib/python3.13/unittest/case.py", line 732, in fail
    raise self.failureException(msg)
    ^^^^^^^^^^^^^^^
AssertionError: '6 ob[100 chars]ion, models, reset_queries\n  from django.db.m[55 chars]zone' != '6 ob[100 chars]ion, reset_queries, models\n  from django.db.m[55 chars]zone'
  6 objects imported automatically:
  
    from django.conf import settings
-   from django.db import connection, models, reset_queries
?                                    --------
+   from django.db import connection, reset_queries, models
?                                                  ++++++++
    from django.db.models import functions
    from django.utils import timezone

I have isort installed as some other Django developer do (but not all) to properly sort imports. The tests should not depend on whether isort is installed or not, so I'm proposing that the default list of utilities to auto import in the shell is also sorted, not only this feels cleaner and more polished, but it also prevents isort mismatches.

@nessita nessita force-pushed the autoimports-shell-failing-test branch from fc0638d to c1202db Compare July 17, 2025 16:09
Copy link
Contributor

@sarahboyce sarahboyce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 👍

@nessita nessita merged commit e767bd6 into django:main Jul 18, 2025
31 of 32 checks passed
@nessita nessita deleted the autoimports-shell-failing-test branch July 18, 2025 11:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants