Skip to content

Commit 799ed7e

Browse files
committed
Re-enable workaround for pytest-django bug
Fixed upstream by: pytest-dev/pytest-django#1275
1 parent d906a5e commit 799ed7e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

tests/conftest.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22

33
from typing import TYPE_CHECKING, Literal
44

5-
from allauth.socialaccount.models import SocialAccount
65
from django.conf import settings
7-
from django.contrib.auth.models import User
8-
from django.contrib.sites.models import Site
96
from django.test import Client
107
from django.urls import reverse
118
import pytest
129

1310
if 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)
4140
def 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
6466
def 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
7580
def 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

Comments
 (0)