Merge pull request #609 from pfouque/fix_unittest

Fix override_config test decorator on Django 5.2
This commit is contained in:
Rémy HUBSCHER 2025-02-04 22:11:22 +01:00 committed by GitHub
commit 22bdb011db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 3 deletions

View file

@ -1,5 +1,6 @@
from functools import wraps
from django import VERSION as DJANGO_VERSION
from django.test import SimpleTestCase
from django.test.utils import override_settings
@ -44,9 +45,19 @@ class override_config(override_settings):
original_pre_setup = test_case._pre_setup
original_post_teardown = test_case._post_teardown
def _pre_setup(inner_self):
self.enable()
original_pre_setup(inner_self)
if DJANGO_VERSION < (5, 2):
def _pre_setup(inner_self):
self.enable()
original_pre_setup(inner_self)
else:
@classmethod
def _pre_setup(cls):
# NOTE: Django 5.2 turned this as a classmethod
# https://github.com/django/django/pull/18514/files
self.enable()
original_pre_setup()
def _post_teardown(inner_self):
original_post_teardown(inner_self)

View file

@ -4,6 +4,7 @@ envlist =
py{38,39,310,311,312}-dj{42}-{unittest,pytest,checkmigrations}
py{310,311,312}-dj{50}-{unittest,pytest,checkmigrations}
py{310,311,312,313}-dj{51}-{unittest,pytest,checkmigrations}
py{310,311,312,313}-dj{52}-{unittest,pytest,checkmigrations}
py{310,311,312,313}-dj{main}-{unittest,pytest,checkmigrations}
skip_missing_interpreters = True
@ -14,6 +15,7 @@ deps =
dj42: django>=4.2,<4.3
dj50: django>=5.0,<5.1
dj51: django>=5.1,<5.2
dj52: django==5.2alpha1
djmain: https://github.com/django/django/archive/main.tar.gz
pytest: pytest
pytest: pytest-cov