Skip to content
Open
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
7 changes: 4 additions & 3 deletions pytest_django/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,10 @@ def _save_active_wrapper(self) -> None:
def _blocking_wrapper(*args: Any, **kwargs: Any) -> NoReturn: # noqa: ARG002
__tracebackhide__ = True
raise RuntimeError(
"Database access not allowed, "
'use the "django_db" mark, or the '
'"db" or "transactional_db" fixtures to enable it.'
"Database access not allowed. "
"Use the @pytest.mark.django_db mark or the db/transactional_db "
"fixtures to enable it. "
"See https://pytest-django.readthedocs.io/en/latest/database.html#database-access"
)

def unblock(self) -> AbstractContextManager[None]:
Expand Down
9 changes: 3 additions & 6 deletions tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,7 @@ def test_db_access_3(self):
"*test_db_access_2 FAILED*",
"*test_db_access_3 FAILED*",
"*ERROR at setup of TestCase_setupClass.test_db_access_1*",
'*RuntimeError: Database access not allowed, use the "django_db" mark, '
'or the "db" or "transactional_db" fixtures to enable it.',
'*RuntimeError: Database access not allowed. Use the @pytest.mark.django_db mark or the db/transactional_db fixtures to enable it. See https://pytest-django.readthedocs.io/en/latest/database.html#database-access'
]
)

Expand Down Expand Up @@ -472,8 +471,7 @@ def test_db_access_in_conftest(self, django_pytester: DjangoPytester) -> None:
result = django_pytester.runpytest_subprocess("-v")
result.stderr.fnmatch_lines(
[
'*RuntimeError: Database access not allowed, use the "django_db" mark, '
'or the "db" or "transactional_db" fixtures to enable it.*'
'*RuntimeError: Database access not allowed. Use the @pytest.mark.django_db mark or the db/transactional_db fixtures to enable it. See https://pytest-django.readthedocs.io/en/latest/database.html#database-access*'
]
)

Expand All @@ -488,7 +486,6 @@ def test_db_access_in_test_module(self, django_pytester: DjangoPytester) -> None
result = django_pytester.runpytest_subprocess("-v")
result.stdout.fnmatch_lines(
[
'*RuntimeError: Database access not allowed, use the "django_db" mark, '
'or the "db" or "transactional_db" fixtures to enable it.'
'*RuntimeError: Database access not allowed. Use the @pytest.mark.django_db mark or the db/transactional_db fixtures to enable it. See https://pytest-django.readthedocs.io/en/latest/database.html#database-access'
]
)
4 changes: 2 additions & 2 deletions tests/test_fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -766,15 +766,15 @@ class Test_django_db_blocker:
def test_block_manually(self, django_db_blocker: DjangoDbBlocker) -> None:
try:
django_db_blocker.block()
with pytest.raises(RuntimeError, match="^Database access not allowed,"):
with pytest.raises(RuntimeError, match="^Database access not allowed\. Use the @pytest\.mark\.django_db mark or the db/transactional_db fixtures to enable it\. See https://pytest-django\.readthedocs\.io/en/latest/database\.html#database-access"):
Item.objects.exists()
finally:
django_db_blocker.restore()

@pytest.mark.django_db
def test_block_with_block(self, django_db_blocker: DjangoDbBlocker) -> None:
with django_db_blocker.block():
with pytest.raises(RuntimeError, match="^Database access not allowed,"):
with pytest.raises(RuntimeError, match="^Database access not allowed\. Use the @pytest\.mark\.django_db mark or the db/transactional_db fixtures to enable it\. See https://pytest-django\.readthedocs\.io/en/latest/database\.html#database-access"):
Item.objects.exists()

def test_unblock_manually(self, django_db_blocker: DjangoDbBlocker) -> None:
Expand Down
Loading