-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
"Database access not allowed" in Doctests (Django) #1180
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
Comments
IIRC doc tests currently can't be marked with pytest marks, so unless you can enable database access somehow using fixture's and the getfixture API, I'm afraid there's no solution currently. Perhaps you could create an issue at pytest-dev/pytest-django to see if there are any known workarounds? |
I tested some more and noticed this: some of the doctests, which are requiring a database connection, run successfully on console, but fail in PyCharm. I could not determine, why some tests run and some don't. I'm now converting my doctests to unittests, which is probably a better practice and causes less problems. |
That's strange, probably some weird interaction with PyCharm's pytest runner (although I'm a PyCharm user and never experienced any problems). Feel free to reopen this if you happen to have new info. |
Sorry to drop a comment on a six-year-old closed issue, but I'm facing this problem currently and am still looking for a fix.
My tests were originally inside docstrings in my codebase, but when the recommended decorators didn't help them pass, I extracted them into a standalone Sanitized output showing the error in response to
|
I'm trying to get database access (django) in a few of my doctests with
or
But I keep getting the following error:
Is Django database access supported in doctests?
My other unittests using the Django database work fine.
I use
pytest 1.8.2.dev1 (#1057)
pytest-django==2.9.1
Django==1.8
The text was updated successfully, but these errors were encountered: