pytest-dev / pytest-dev/pytest-django
Live server error with sqlite3
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.5k
- Forks
- 367
- PR merge metrics
- No merged PRs in 30d
Description
When using the live_server in an integration test fixture:
@pytest.fixture(scope='session', name='server_url')
def get_server_url(live_server, environment):
"""Start a django server to test against and return the url of the server."""
yield live_server.url
the following error is generated:
self = <[AttributeError("'LiveServer' object has no attribute 'thread'") raised in repr()] LiveServer object at 0x80526a8d0>
addr = 'localhost'
def __init__(self, addr):
import django
from django.db import connections
from django.test.testcases import LiveServerThread
from django.test.utils import modify_settings
connections_override = {}
for conn in connections.all():
# If using in-memory sqlite databases, pass the connections to
# the server thread.
if (
conn.settings_dict["ENGINE"] == "django.db.backends.sqlite3"
and conn.settings_dict["NAME"] == ":memory:"
):
# Explicitly enable thread-shareability for this connection
> conn.allow_thread_sharing = True
E AttributeError: can't set attribute
/home/goldeneagle/venv/lib/python3.7/site-packages/pytest_django/live_server_helper.py:27: AttributeError
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in pytest_django/live_server_helper.py at LiveServer.init, then inspect the Django connection and LiveServerThread behavior shown in the traceback. Reproduce the session-scoped live_server fixture with an in-memory SQLite database and verify that the server starts without the allow_thread_sharing AttributeError.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- django, python, sqlite
- Domain
- backend, database, testing
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100