Skip to content

Commit f0523aa

Browse files
bckohansobolevn
andauthored
Support Django 5.2, Upgrade to Poetry 2.x (#504)
* add django 5.2b1 to CI matrix to illustrate #503 * add django 5.2 compatible postgres db to docker compose * tweak unittest to illustrate #503 bug * pass lint * second attempt to make the linter happy * are you kidding me? lol * codecov-action file is deprecated - use files isntead * Fix unit target in makefile, spaces instead of tabs meant tests were not being run. Use alternate port for second postgres container. Override setUpClass to illustrate the bug * fix #503. We simply convert the _pre_setup to a classmethod. Its fine that it only runs once for all tests on the class. The receivers are restored to the originals each time. * upgrade to poetry 2.x * silence deprecation warning by removing unnecessary i18n setting * switch _pre_setup definition based on django version * because we now have different code paths depending on django versions we need to aggregate our coverage files from all CI jobs to see the real total * fail CI if aggregated coverage is less than 100 * make coverage file name artifacts unique * add missing poetry instal to coverage-combine * fix coverage tool combine invocations to use poetry run * Update pyproject.toml Co-authored-by: sobolevn <[email protected]> * revert back to failing on <100% test coverage - exempt _pre_setup from coverage * fix requires-python - uv balked at the carrot format? * remove coverage aggregation * update lock file --------- Co-authored-by: sobolevn <[email protected]>
1 parent d584f03 commit f0523aa

File tree

8 files changed

+490
-417
lines changed

8 files changed

+490
-417
lines changed

.github/workflows/test.yml

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,11 @@ jobs:
2727
strategy:
2828
fail-fast: false
2929
matrix:
30-
python-version: ['3.10', '3.11', '3.12']
30+
python-version: ['3.10', '3.11', '3.12', '3.13']
3131
django-version:
3232
- 'Django~=4.2.0'
3333
- 'Django~=5.0.0'
34+
- 'Django==5.2b1'
3435
docker-compose-services: ['']
3536
additional-dependencies: ['']
3637
env: [{}]
@@ -50,6 +51,14 @@ jobs:
5051
env:
5152
DJANGO_DATABASE_ENGINE: 'django.db.backends.postgresql'
5253
DJANGO_DATABASE_PORT: 5432
54+
55+
- python-version: '3.13'
56+
django-version: 'Django==5.2b1'
57+
docker-compose-services: postgresql-db-17
58+
additional-dependencies: psycopg
59+
env:
60+
DJANGO_DATABASE_ENGINE: 'django.db.backends.postgresql'
61+
DJANGO_DATABASE_PORT: 5433
5362
# TODO: reenable
5463
# - python-version: '3.12'
5564
# django-version: 'Django~=5.0.0'
@@ -130,7 +139,8 @@ jobs:
130139
- name: Upload coverage to Codecov
131140
uses: codecov/codecov-action@v5
132141
with:
133-
file: ./coverage.xml
142+
files:
143+
./coverage.xml
134144

135145
- name: Stop docker-compose services
136146
if: ${{ always() && matrix.docker-compose-services }}

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ lint:
77

88
.PHONY: unit
99
unit:
10-
# We need one more test run to make sure that `--nomigrations` work:
11-
poetry run pytest -p no:cov -o addopts="" --nomigrations
10+
# We need one more test run to make sure that `--nomigrations` work:
11+
poetry run pytest -p no:cov -o addopts="" --nomigrations
1212
poetry run pytest
1313

1414
.PHONY: package

django_test_app/django_test_app/settings.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@
123123

124124
USE_I18N = True
125125

126-
USE_L10N = True
127-
128126
USE_TZ = True
129127

130128

django_test_migrations/contrib/unittest_case.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
from typing import ClassVar, Optional
1+
from typing import Any, ClassVar, List, Optional
22

3+
import django
34
from django.db.migrations.state import ProjectState
45
from django.db.models.signals import post_migrate, pre_migrate
56
from django.test import TransactionTestCase, tag
@@ -21,6 +22,10 @@ class MigratorTestCase(TransactionTestCase):
2122
migrate_from: ClassVar[MigrationSpec]
2223
migrate_to: ClassVar[MigrationSpec]
2324

25+
# hold original receivers to restore them after each test
26+
_pre_migrate_receivers: List[Any]
27+
_post_migrate_receivers: List[Any]
28+
2429
def setUp(self) -> None:
2530
"""
2631
Regular ``unittest`` styled setup case.
@@ -54,11 +59,21 @@ def tearDown(self) -> None:
5459
self._migrator.reset()
5560
super().tearDown()
5661

57-
def _pre_setup(self) -> None:
58-
self._pre_migrate_receivers, pre_migrate.receivers = ( # noqa: WPS414
62+
@classmethod
63+
def _store_receivers(cls) -> None:
64+
cls._pre_migrate_receivers, pre_migrate.receivers = ( # noqa: WPS414
5965
pre_migrate.receivers, [],
6066
)
61-
self._post_migrate_receivers, post_migrate.receivers = ( # noqa: WPS414
67+
cls._post_migrate_receivers, post_migrate.receivers = ( # noqa: WPS414
6268
post_migrate.receivers, [],
6369
)
64-
super()._pre_setup() # type: ignore[misc]
70+
71+
if django.VERSION[:2] < (5, 2): # noqa: WPS604 # pragma: no cover
72+
def _pre_setup(self) -> None:
73+
self._store_receivers()
74+
super()._pre_setup() # type: ignore[misc]
75+
else: # pragma: no cover
76+
@classmethod
77+
def _pre_setup(cls) -> None: # type: ignore[misc] # noqa: WPS614,WPS440
78+
cls._store_receivers()
79+
super()._pre_setup() # type: ignore[misc]

docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,15 @@ services:
1111
- POSTGRES_PASSWORD=passwd123
1212
- POSTGRES_DB=db
1313

14+
postgresql-db-17:
15+
image: postgres:17
16+
ports:
17+
- "5433:5432"
18+
environment:
19+
- POSTGRES_USER=django
20+
- POSTGRES_PASSWORD=passwd123
21+
- POSTGRES_DB=db
22+
1423
mysql-db:
1524
image: mysql:8
1625
ports:

poetry.lock

Lines changed: 429 additions & 397 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
[tool.poetry]
1+
[project]
22
name = "django-test-migrations"
33
version = "1.4.0"
4+
requires-python = ">=3.9,<4.0"
45
description = "Test django schema and data migrations, including ordering"
56
license = "MIT"
6-
7+
license-files = [ "LICENSE" ]
78
authors = [
8-
"sobolevn <[email protected]>"
9+
{name = "sobolevn", email = "[email protected]"},
910
]
1011

1112
readme = "README.md"
@@ -38,17 +39,20 @@ classifiers = [
3839
"Framework :: Django :: 4.1",
3940
"Framework :: Django :: 4.2",
4041
"Framework :: Django :: 5.0",
42+
"Framework :: Django :: 5.1",
43+
"Framework :: Django :: 5.2",
44+
]
45+
46+
dependencies = [
47+
"typing_extensions>=4.0"
4148
]
4249

43-
[tool.poetry.plugins.pytest11]
50+
[project.entry-points."pytest11"]
4451
django_test_migrations = "django_test_migrations.contrib.pytest_plugin"
4552

46-
[tool.poetry.dependencies]
47-
python = "^3.9"
48-
typing_extensions = ">=4.0"
4953

5054
[tool.poetry.group.dev.dependencies]
51-
django = "^4.2"
55+
django = ">=4.2,<6.0"
5256

5357
mypy = "^1.11"
5458
django-stubs = "^5.0"
@@ -65,7 +69,7 @@ pytest-mock = "^3.14"
6569

6670

6771
[build-system]
68-
requires = ["poetry-core>=1.9.0"]
72+
requires = ["poetry-core>=2.1.0"]
6973
build-backend = "poetry.core.masonry.api"
7074

7175

tests/test_contrib/test_unittest_case/test_unittest_case.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ class TestDirectMigration(MigratorTestCase):
88
migrate_from = ('main_app', '0002_someitem_is_clean')
99
migrate_to = ('main_app', '0003_update_is_clean')
1010

11+
@classmethod
12+
def setUpClass(cls):
13+
"""Override parent's setUpClass to trigger #503."""
14+
super().setUpClass()
15+
1116
def prepare(self):
1217
"""Prepare some data before the migration."""
1318
SomeItem = self.old_state.apps.get_model('main_app', 'SomeItem')

0 commit comments

Comments
 (0)