Skip to content

Fix _disable_native_migrations: only set verbosity=0 #730

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions pytest_django/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,18 @@ class ResetSequenceTestCase(django_case):

def _disable_native_migrations():
from django.conf import settings
from django.core.management.commands.migrate import Command
from django.core.management.commands import migrate

from .migrations import DisableMigrations

settings.MIGRATION_MODULES = DisableMigrations()

def migrate_noop(self, *args, **kwargs):
pass
class MigrateSilentCommand(migrate.Command):
def handle(self, *args, **kwargs):
kwargs["verbosity"] = 0
return super(MigrateSilentCommand, self).handle(*args, **kwargs)

Command.handle = migrate_noop
migrate.Command = MigrateSilentCommand


# ############### User visible fixtures ################
Expand Down
10 changes: 6 additions & 4 deletions tests/test_db_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@ def test_no_migrations(self, django_testdir):

@pytest.mark.django_db
def test_inner_migrations():
pass
from .app.models import Item
Item.objects.create()
"""
)

Expand All @@ -340,11 +341,11 @@ def test_inner_migrations():
)

result = django_testdir.runpytest_subprocess(
"--nomigrations", "--tb=short", "-vv",
"--nomigrations", "--tb=short", "-vv", "-s",
)
assert result.ret == 0
assert "Operations to perform:" not in result.stdout.str()
result.stdout.fnmatch_lines(["*test_inner_migrations*PASSED*"])
result.stdout.fnmatch_lines(["*= 1 passed in *"])

def test_migrations_run(self, django_testdir):
testdir = django_testdir
Expand All @@ -354,7 +355,8 @@ def test_migrations_run(self, django_testdir):

@pytest.mark.django_db
def test_inner_migrations():
pass
from .app.models import Item
Item.objects.create()
"""
)

Expand Down