From 947e47ec3f7d9fc8fe6f0d71cde500e64c6dc870 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 6 May 2019 10:22:25 +0200 Subject: [PATCH 1/2] Fix _disable_native_migrations: only set verbosity=0 --- pytest_django/fixtures.py | 10 ++++++---- tests/test_db_setup.py | 8 +++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pytest_django/fixtures.py b/pytest_django/fixtures.py index 0c8606f26..94d77dd24 100644 --- a/pytest_django/fixtures.py +++ b/pytest_django/fixtures.py @@ -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 ################ diff --git a/tests/test_db_setup.py b/tests/test_db_setup.py index de64c793e..e9b8cf7d9 100644 --- a/tests/test_db_setup.py +++ b/tests/test_db_setup.py @@ -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() """ ) @@ -340,7 +341,7 @@ 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() @@ -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() """ ) From 45bb3ab73b26ef51a8394d256717b625220507ce Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Mon, 6 May 2019 10:32:06 +0200 Subject: [PATCH 2/2] fixup! Fix _disable_native_migrations: only set verbosity=0 --- tests/test_db_setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_db_setup.py b/tests/test_db_setup.py index e9b8cf7d9..2ce4b6430 100644 --- a/tests/test_db_setup.py +++ b/tests/test_db_setup.py @@ -345,7 +345,7 @@ def test_inner_migrations(): ) 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