1414)
1515from common .projects .permissions import VIEW_PROJECT
1616from django .contrib .contenttypes .models import ContentType
17+ from django .contrib .postgres .signals import (
18+ register_type_handlers ,
19+ )
1720from django .core .cache import caches
1821from django .db .backends .base .creation import TEST_DATABASE_PREFIX
1922from django .test .utils import setup_databases
2225from mypy_boto3_dynamodb .service_resource import DynamoDBServiceResource , Table
2326from pyfakefs .fake_filesystem import FakeFilesystem
2427from pytest import FixtureRequest
28+ from pytest_django import DjangoDbBlocker
2529from pytest_django .fixtures import SettingsWrapper
2630from pytest_django .plugin import blocking_manager_key
2731from pytest_mock import MockerFixture
@@ -158,7 +162,10 @@ def fs(fs: FakeFilesystem) -> FakeFilesystem:
158162
159163
160164@pytest .fixture (scope = "session" )
161- def django_db_setup (request : pytest .FixtureRequest ) -> None :
165+ def django_db_setup (
166+ request : pytest .FixtureRequest ,
167+ django_db_blocker : DjangoDbBlocker ,
168+ ) -> None :
162169 if (
163170 request .config .option .ci
164171 # xdist worker id is either `gw[0-9]+` or `master`
@@ -177,6 +184,15 @@ def django_db_setup(request: pytest.FixtureRequest) -> None:
177184 test_db_name = f"{ TEST_DATABASE_PREFIX } { db_settings ['NAME' ]} _{ test_db_suffix } "
178185 db_settings ["NAME" ] = test_db_name
179186
187+ from django .db import connections
188+
189+ # Ensure psycopg type handlers are registered.
190+ # This is necessary for tests that involve `HStoreField`.
191+ for connection in connections .all ():
192+ if connection .vendor == "postgresql" :
193+ with django_db_blocker .unblock ():
194+ register_type_handlers (connection )
195+
180196
181197@pytest .fixture (autouse = True )
182198def restrict_http_requests (monkeypatch : pytest .MonkeyPatch ) -> None :
0 commit comments