Skip to content

Commit

Permalink
Remove django monkey patch from reusedb
Browse files Browse the repository at this point in the history
  • Loading branch information
millerdev committed Jul 1, 2024
1 parent d965df5 commit 6525103
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
12 changes: 5 additions & 7 deletions corehq/tests/pytest_plugins/reusedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from unittest.mock import Mock, patch

import pytest
from pytest_django import fixtures as django_fixtures
from pytest_django.fixtures import (
db as django_db,
django_db_modify_db_settings,
Expand All @@ -43,6 +44,7 @@

from corehq.util.test_utils import timelimit, unit_testing_only

from .util import override_fixture
from ..tools import nottest

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -172,18 +174,14 @@ def is_still_sorted(items, key):
return all(new_key(a) <= new_key(b) for a, b in zip(items, it))


@pytest.fixture(scope="session")
@override_fixture(django_fixtures.django_db_setup)
@use(django_db_modify_db_settings)
def django_db_setup():
"""Override pytest_django's django_db_setup fixture
"""Override pytest-django's django_db_setup fixture
Replace pytest_django's database setup/teardown with
Replace pytest-django's database setup/teardown with
DeferredDatabaseContext, which handles other databases
including Couch, Elasticsearch, BlobDB, and Redis.
There appears to be no explicit dependency between this and the
pytest-django fixture. Is there a race to determine which will
override the other? Beware of magic.
"""
try:
yield
Expand Down
12 changes: 12 additions & 0 deletions corehq/tests/pytest_plugins/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from functools import wraps


def override_fixture(old_fixture):
"""Override a pytest magic fixture with an unmagic fixture"""
def apply(new_fixture):
@wraps(new_fixture)
def fixture(*a, **k):
yield from new_fixture(*a, **k)
old_fixture.__pytest_wrapped__.obj = fixture
return new_fixture
return apply

0 comments on commit 6525103

Please sign in to comment.