Skip to content
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

tests: run Test_django_db_blocker in testdir #806

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
58 changes: 35 additions & 23 deletions tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,32 +601,44 @@ class Migration(migrations.Migration):
assert result.ret == 0


class Test_django_db_blocker:
@pytest.mark.django_db
def test_block_manually(self, django_db_blocker):
try:
django_db_blocker.block()
with pytest.raises(RuntimeError):
Item.objects.exists()
finally:
django_db_blocker.restore()
def test_django_db_blocker(testdir):
p1 = testdir.makepyfile("""
import django.db.utils
import pytest

@pytest.mark.django_db
def test_block_with_block(self, django_db_blocker):
with django_db_blocker.block():
with pytest.raises(RuntimeError):
Item.objects.exists()
from pytest_django_test.app.models import Item

def test_unblock_manually(self, django_db_blocker):
try:
django_db_blocker.unblock()
Item.objects.exists()
finally:
django_db_blocker.restore()

def test_unblock_with_block(self, django_db_blocker):
with django_db_blocker.unblock():
Item.objects.exists()
@pytest.mark.django_db
def test_block_manually(django_db_blocker):
try:
django_db_blocker.block()
with pytest.raises(RuntimeError):
Item.objects.exists()
finally:
django_db_blocker.restore()

@pytest.mark.django_db
def test_block_with_block(django_db_blocker):
with django_db_blocker.block():
with pytest.raises(RuntimeError):
Item.objects.exists()

def test_unblock_manually(django_db_blocker):
try:
django_db_blocker.unblock()
with pytest.raises(django.db.utils.OperationalError):
Item.objects.exists()
finally:
django_db_blocker.restore()

def test_unblock_with_block(django_db_blocker):
with django_db_blocker.unblock():
with pytest.raises(django.db.utils.OperationalError):
Item.objects.exists()
""")
result = testdir.runpytest_subprocess("-vv", "-rA", "--tb=short", str(p1))
assert result.ret == 0


def test_mail(mailoutbox):
Expand Down