pytest-dev / pytest-dev/pytest-django

Doctest intermittently getting "Failed: Database access not allowed, use the "django_db" mark to enable"

Open
#302 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

documentation enhancement
Dominant language
Python
Stars
1.5k
Forks
367
PR merge metrics
No merged PRs in 30d

Description

Using Python 3.4, pytest-django 2.8.0, pytest 2.7.0, django 1.7.6, & Postgresql 9.3.9

When running my unit tests I have an intermittent error returning from my one and only Doctest. All my unit tests pass just fine and many use the database. Here's my test invocation:
time py.test -n 7 -s -v --durations=10

273 Goals must be created within the context of a Portfolio.
274 >>> import pytest
275 >>> pytestmark = pytest.mark.django_db()
276 >>> from portfolio.models import Portfolio
277 >>> p, new = Portfolio.objects.get_or_create(name="Sample Goals")
UNEXPECTED EXCEPTION: Database access not allowed, use the "django_db" mark to enable

Removing lines 274 & 275 have no impact.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin with the doctest at lines 273-277 and reproduce it using py.test -n 7 -s -v --durations=10 under the listed versions. Trace why pytestmark = pytest.mark.django_db() does not enable database access intermittently; done means the doctest no longer reports this error.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, postgresql, python
Domain
databases, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.