pytest-django
pytest-django copied to clipboard
Move thread activation to start method
trafficstars
This moves activation of LiveServer.thread to a method. My primary motivation here is to delay thread activation so I can change the parameters of the thread in an overriden live_server fixture. This provides a work-around to issue #294 using the following override:
import pytest
from pytest_django import live_server_helper
from pytest_django.lazy_django import skip_if_no_django
@pytest.fixture(scope="session")
def live_server(request):
skip_if_no_django()
addr = (
request.config.getvalue("liveserver")
or os.getenv("DJANGO_LIVE_TEST_SERVER_ADDRESS")
or "localhost"
)
server = live_server_helper.LiveServer(addr)
server.thread.static_handler = _StaticFilesHandler
server.start()
request.addfinalizer(server.stop)
return server