Skip to content

Commit 264502c

Browse files
committed
fixup! fixup! live_server: use Django's LiveServerTestCase for setup/teardown
1 parent 7075d70 commit 264502c

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

pytest_django/fixtures.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,11 @@ def _live_server_helper(request):
435435

436436
live_server = request.getfixturevalue("live_server")
437437

438+
modified_settings = live_server._dj_testcase._live_server_modified_settings
439+
if not hasattr(modified_settings, "wrapped"):
440+
modified_settings.enable()
441+
request.addfinalizer(modified_settings.disable)
442+
438443

439444
@contextmanager
440445
def _assert_num_queries(config, num, exact=True, connection=None, info=None):

pytest_django/live_server_helper.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import django
21
import six
32

43

@@ -12,11 +11,21 @@ class LiveServer(object):
1211

1312
def __init__(self, addr):
1413
from django.test.testcases import LiveServerTestCase
14+
from django.conf import settings
1515

16-
self._dj_testcase = LiveServerTestCase("__init__")
16+
if "django.contrib.staticfiles" in settings.INSTALLED_APPS:
17+
from django.contrib.staticfiles.handlers import StaticFilesHandler
18+
else:
19+
from django.test.testcases import _StaticFilesHandler as StaticFilesHandler
20+
21+
class CustomLiveServerTestCase(LiveServerTestCase):
22+
static_handler = StaticFilesHandler
23+
24+
self._dj_testcase = CustomLiveServerTestCase("__init__")
1725
self._dj_testcase.setUpClass()
1826

1927
def stop(self):
28+
self._dj_testcase._live_server_modified_settings.enable()
2029
self._dj_testcase.tearDownClass()
2130

2231
@property

0 commit comments

Comments
 (0)