Skip to content

Commit 389a8b1

Browse files
committed
Re-enable workaround for pytest-django bug
Fixed upstream by: pytest-dev/pytest-django#1275
1 parent d92e08c commit 389a8b1

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

tests/conftest.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@
22

33
from typing import TYPE_CHECKING, Any, Literal
44

5-
from allauth.account.models import EmailAddress
6-
from allauth.socialaccount.models import SocialAccount
7-
from allauth.usersessions.models import UserSession
85
from django.conf import settings
9-
from django.contrib.auth.models import User
10-
from django.contrib.sites.models import Site
116
from django.test import Client
127
import pytest
138

149
if TYPE_CHECKING:
15-
# Work around https://github.com/pytest-dev/pytest-django/issues/1152
1610
from collections.abc import Callable
1711

12+
from allauth.socialaccount.models import SocialAccount
13+
from django.contrib.auth.models import User
14+
from django.contrib.sites.models import Site
1815
from playwright.sync_api import BrowserContext, Page
1916
from pytest_django.fixtures import SettingsWrapper
2017
from pytest_django.live_server_helper import LiveServer
@@ -40,6 +37,9 @@ def mock_generate_seed(mocker: MockerFixture) -> MockType:
4037

4138
@pytest.fixture(autouse=True)
4239
def default_site(transactional_db: None) -> Site:
40+
# Work around https://github.com/pytest-dev/pytest-django/issues/1152
41+
from django.contrib.sites.models import Site # noqa: PLC0415
42+
4343
# The default site is created via the "post_migrate" signal and TransactionTestCase
4444
# specifically re-sends the "post_migrate" signal after flushing the database between each test.
4545
# So, the default site is guaranteed to exist for each test, but with its original value.
@@ -63,6 +63,10 @@ def mock_recently_authenticated(mocker: MockerFixture, settings: SettingsWrapper
6363

6464
@pytest.fixture
6565
def user(transactional_db: None) -> User:
66+
# Work around https://github.com/pytest-dev/pytest-django/issues/1152
67+
from allauth.account.models import EmailAddress # noqa: PLC0415
68+
from django.contrib.auth.models import User # noqa: PLC0415
69+
6670
user = User.objects.create_user(
6771
username="test_user",
6872
first_name="Test",
@@ -82,6 +86,9 @@ def user(transactional_db: None) -> User:
8286

8387
@pytest.fixture
8488
def social_account(transactional_db: None, user: User) -> SocialAccount:
89+
# Work around https://github.com/pytest-dev/pytest-django/issues/1152
90+
from allauth.socialaccount.models import SocialAccount # noqa: PLC0415
91+
8592
return SocialAccount.objects.create(
8693
user=user,
8794
provider="dummy",
@@ -146,6 +153,9 @@ def authenticated_context(
146153
user: User,
147154
mock_recently_authenticated: MockType,
148155
) -> BrowserContext:
156+
# Work around https://github.com/pytest-dev/pytest-django/issues/1152
157+
from allauth.usersessions.models import UserSession # noqa: PLC0415
158+
149159
# Use force_login + cookie injection instead of filling the login form for speed.
150160
client.force_login(user)
151161
session_cookie = client.cookies[settings.SESSION_COOKIE_NAME]

0 commit comments

Comments
 (0)