Opened 3 hours ago

Last modified 47 minutes ago

#35934 assigned Cleanup/optimization

Migrations tests fail and leave behind files if tests/migrations/migrations exists

Reported by: Jacob Walls Owned by: Jacob Walls
Component: Migrations Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

% ./runtests.py -k migrations
% git status
Untracked files:
  (use "git add <file>..." to include in what will be committed)
        migrations/migrations/

Change History (2)

comment:1 by Tim Graham, 80 minutes ago

Hi Jacob, I can't reproduce it. Can you debug it further on your system?

comment:2 by Jacob Walls, 47 minutes ago

Owner: set to Jacob Walls
Status: newassigned
Summary: Running the migrations tests leaves a dirty git statusMigrations tests fail and leave behind files if tests/migrations/migrations exists

Sure thing, turns out I only encountered this because I had an extra directory left around from writing/debugging other tests, and merely deleting the files to get back to a clean git status didn't remove the directory causing the problem, leaving me a bit confused.

To reproduce:

cd tests
mkdir migrations/migrations
./runtests.py migrations.test_commands.MakeMigrationsTests.test_makemigrations_empty_connections
git status

Then, besides a dirty git status, that single test also fails...:

F
======================================================================
FAIL: test_makemigrations_empty_connections (migrations.test_commands.MakeMigrationsTests.test_makemigrations_empty_connections)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/jwalls/django/tests/migrations/test_commands.py", line 1551, in test_makemigrations_empty_connections
    self.assertIn("No changes detected", out.getvalue())
AssertionError: 'No changes detected' not found in "\x1b[36;1mMigrations for 'migrations':\x1b[0m\n  \x1b[1mmigrations/migrations/0001_initial.py\x1b[0m\n    + Create model ModelWithCustomBase\n    + Create model UnmigratedModel\n"

----------------------------------------------------------------------
Ran 1 test in 0.102s

FAILED (failures=1)

...however, when running the whole migrations tests, several more tests fail with distinct outputs, further obscuring the source of the problem.

A sanity check like might make the failures less mysterious? I won't be disappointed if it's a wontfix.

  • tests/migrations/test_commands.py

    diff --git a/tests/migrations/test_commands.py b/tests/migrations/test_commands.py
    index 724c88a28f..3c7ce451f6 100644
    a b class MakeMigrationsTests(MigrationTestBase):  
    14891489    def setUp(self):
    14901490        super().setUp()
    14911491        self._old_models = apps.app_configs["migrations"].models.copy()
     1492        self.assertFalse(os.path.exists("migrations"))
    14921493
    14931494    def tearDown(self):
    14941495        apps.app_configs["migrations"].models = self._old_models
Note: See TracTickets for help on using tickets.
Back to Top