Skip to content

Commit 9026e18

Browse files
committed
Merge pull request pytest-dev#201 from pytest-dev/cleanup-live_server-transactional_db-interaction
Cleanup interaction with `live_server` and `transactional_db`
2 parents 55f5ddd + 93dabf2 commit 9026e18

File tree

2 files changed

+5
-10
lines changed

2 files changed

+5
-10
lines changed

pytest_django/fixtures.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ def flushdb():
8383
request.addfinalizer(_django_cursor_wrapper.disable)
8484
request.addfinalizer(flushdb)
8585
else:
86-
if 'live_server' in request.funcargnames:
87-
return
8886
from django.test import TestCase
8987

9088
_django_cursor_wrapper.enable()
@@ -158,7 +156,8 @@ def db(request, _django_db_setup, _django_cursor_wrapper):
158156
database setup will behave as only ``transactional_db`` was
159157
requested.
160158
"""
161-
if 'transactional_db' in request.funcargnames:
159+
if 'transactional_db' in request.funcargnames \
160+
or 'live_server' in request.funcargnames:
162161
return request.getfuncargvalue('transactional_db')
163162
return _django_db_fixture_helper(False, request, _django_cursor_wrapper)
164163

tests/test_fixtures.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,11 @@ def test_fixture_transactional_db(self, transactional_db, live_server):
118118

119119
@pytest.fixture
120120
def item(self):
121-
# This has not requested database access so should fail.
122-
# Unfortunately the _live_server_helper autouse fixture makes this
123-
# test work.
124-
with pytest.raises(pytest.fail.Exception):
125-
Item.objects.create(name='foo')
121+
# This has not requested database access explicitly, but the
122+
# live_server fixture auto-uses the transactional_db fixture.
123+
Item.objects.create(name='foo')
126124

127-
@pytest.mark.xfail
128125
def test_item(self, item, live_server):
129-
# test should fail/pass in setup
130126
pass
131127

132128
@pytest.fixture

0 commit comments

Comments
 (0)