22
33from typing import TYPE_CHECKING , Literal
44
5- from allauth .socialaccount .models import SocialAccount
65from django .conf import settings
7- from django .contrib .auth .models import User
8- from django .contrib .sites .models import Site
96from django .test import Client
107from django .urls import reverse
118import pytest
129
1310if TYPE_CHECKING :
14- # Work around https://github.com/pytest-dev/pytest-django/issues/1152
1511 from collections .abc import Callable
1612
13+ from allauth .socialaccount .models import SocialAccount
14+ from django .contrib .auth .models import User
15+ from django .contrib .sites .models import Site
1716 from playwright .sync_api import BrowserContext , Page
1817 from pytest_django .fixtures import SettingsWrapper
1918 from pytest_django .live_server_helper import LiveServer
@@ -39,6 +38,9 @@ def mock_generate_seed(mocker: MockerFixture) -> MockType:
3938
4039@pytest .fixture (autouse = True )
4140def default_site (transactional_db : None ) -> Site :
41+ # Work around https://github.com/pytest-dev/pytest-django/issues/1152
42+ from django .contrib .sites .models import Site # noqa: PLC0415
43+
4244 # The default site is created via the "post_migrate" signal and TransactionTestCase
4345 # specifically re-sends the "post_migrate" signal after flushing the database between each test.
4446 # So, the default site is guaranteed to exist for each test, but with its original value.
@@ -62,6 +64,9 @@ def mock_recently_authenticated(mocker: MockerFixture, settings: SettingsWrapper
6264
6365@pytest .fixture
6466def user (transactional_db : None ) -> User :
67+ # Work around https://github.com/pytest-dev/pytest-django/issues/1152
68+ from django .contrib .auth .models import User # noqa: PLC0415
69+
6570 return User .objects .create_user (
6671 username = "test_user" ,
6772 first_name = "Test" ,
@@ -73,6 +78,9 @@ def user(transactional_db: None) -> User:
7378
7479@pytest .fixture
7580def social_account (transactional_db : None , user : User ) -> SocialAccount :
81+ # Work around https://github.com/pytest-dev/pytest-django/issues/1152
82+ from allauth .socialaccount .models import SocialAccount # noqa: PLC0415
83+
7684 return SocialAccount .objects .create (
7785 user = user ,
7886 provider = "dummy" ,
0 commit comments