Skip to content

Commit 726956b

Browse files
authored
Fix _disable_native_migrations: only set verbosity=0 (#730)
1 parent 7b34c28 commit 726956b

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

pytest_django/fixtures.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,16 +155,18 @@ class ResetSequenceTestCase(django_case):
155155

156156
def _disable_native_migrations():
157157
from django.conf import settings
158-
from django.core.management.commands.migrate import Command
158+
from django.core.management.commands import migrate
159159

160160
from .migrations import DisableMigrations
161161

162162
settings.MIGRATION_MODULES = DisableMigrations()
163163

164-
def migrate_noop(self, *args, **kwargs):
165-
pass
164+
class MigrateSilentCommand(migrate.Command):
165+
def handle(self, *args, **kwargs):
166+
kwargs["verbosity"] = 0
167+
return super(MigrateSilentCommand, self).handle(*args, **kwargs)
166168

167-
Command.handle = migrate_noop
169+
migrate.Command = MigrateSilentCommand
168170

169171

170172
# ############### User visible fixtures ################

tests/test_db_setup.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ def test_no_migrations(self, django_testdir):
327327
328328
@pytest.mark.django_db
329329
def test_inner_migrations():
330-
pass
330+
from .app.models import Item
331+
Item.objects.create()
331332
"""
332333
)
333334

@@ -340,11 +341,11 @@ def test_inner_migrations():
340341
)
341342

342343
result = django_testdir.runpytest_subprocess(
343-
"--nomigrations", "--tb=short", "-vv",
344+
"--nomigrations", "--tb=short", "-vv", "-s",
344345
)
345346
assert result.ret == 0
346347
assert "Operations to perform:" not in result.stdout.str()
347-
result.stdout.fnmatch_lines(["*test_inner_migrations*PASSED*"])
348+
result.stdout.fnmatch_lines(["*= 1 passed in *"])
348349

349350
def test_migrations_run(self, django_testdir):
350351
testdir = django_testdir
@@ -354,7 +355,8 @@ def test_migrations_run(self, django_testdir):
354355
355356
@pytest.mark.django_db
356357
def test_inner_migrations():
357-
pass
358+
from .app.models import Item
359+
Item.objects.create()
358360
"""
359361
)
360362

0 commit comments

Comments
 (0)