-
Notifications
You must be signed in to change notification settings - Fork 348
Closed
Milestone
Description
I think the following code looks weird ,because it reads like it would disable the DB.
@pytest.fixture
def myfixture(django_db_blocker):
with django_db_blocker:
... # modify something in the database
But that's a manager/fixture I would like to have.
What I came up with is this, meant to work with pytest-django master and 2.9.1:
@pytest.yield_fixture
def disable_db(request):
from _pytest.python import FixtureLookupError
try:
manager = request.getfuncargvalue('django_db_blocker')
manager.disable_database_access()
yield
manager.restore_previous_access()
except FixtureLookupError:
manager = request.getfuncargvalue('_django_cursor_wrapper')
manager.disable()
yield
manager.restore()