Skip to content

Commit 84f576b

Browse files
a3kovPhotonios
authored andcommitted
Skip partitioning tests that depend on Postgres >= 11 if not available
1 parent d1f2d68 commit 84f576b

File tree

4 files changed

+43
-0
lines changed

4 files changed

+43
-0
lines changed

tests/conftest.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,25 @@ def fake_app():
2323

2424
with define_fake_app() as fake_app:
2525
yield fake_app
26+
27+
28+
@pytest.fixture
29+
def postgres_server_version(db) -> int:
30+
"""Gets the PostgreSQL server version."""
31+
32+
return connection.cursor().connection.server_version
33+
34+
35+
@pytest.fixture(autouse=True)
36+
def _apply_postgres_version_marker(request, postgres_server_version):
37+
"""Skip tests based on Postgres server version number marker condition."""
38+
39+
marker = request.node.get_closest_marker("postgres_version")
40+
if not marker:
41+
return
42+
43+
lt = marker.kwargs.get("lt")
44+
if lt and postgres_server_version < lt:
45+
pytest.skip(
46+
f"Server version is {postgres_server_version}, the test needs {lt} or newer."
47+
)

tests/test_migration_operations.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def _create_model(method):
8383
return _create_model
8484

8585

86+
@pytest.mark.postgres_version(lt=110000)
8687
@pytest.mark.parametrize("method", PostgresPartitioningMethod.all())
8788
def test_migration_operations_create_partitioned_table(method, create_model):
8889
"""Tests whether the see :PostgresCreatePartitionedModel operation works as
@@ -100,6 +101,7 @@ def test_migration_operations_create_partitioned_table(method, create_model):
100101
assert not _partitioned_table_exists(create_operation)
101102

102103

104+
@pytest.mark.postgres_version(lt=110000)
103105
@pytest.mark.parametrize("method", PostgresPartitioningMethod.all())
104106
def test_migration_operations_delete_partitioned_table(method, create_model):
105107
"""Tests whether the see :PostgresDeletePartitionedModel operation works as
@@ -131,6 +133,7 @@ def test_migration_operations_delete_partitioned_table(method, create_model):
131133
assert _partitioned_table_exists(create_operation)
132134

133135

136+
@pytest.mark.postgres_version(lt=110000)
134137
@pytest.mark.parametrize(
135138
"method,add_partition_operation",
136139
[
@@ -184,6 +187,7 @@ def test_migration_operations_add_partition(
184187
assert not _partition_exists(create_operation, add_partition_operation)
185188

186189

190+
@pytest.mark.postgres_version(lt=110000)
187191
@pytest.mark.parametrize(
188192
"method,add_partition_operation,delete_partition_operation",
189193
[

tests/test_partitioning_time.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def _get_partitioned_table(model):
2121
return db_introspection.get_partitioned_table(model._meta.db_table)
2222

2323

24+
@pytest.mark.postgres_version(lt=110000)
2425
def test_partitioning_time_yearly_apply():
2526
"""Tests whether automatically creating new partitions ahead yearly works
2627
as expected."""
@@ -56,6 +57,7 @@ def test_partitioning_time_yearly_apply():
5657
assert table.partitions[2].name == "2021"
5758

5859

60+
@pytest.mark.postgres_version(lt=110000)
5961
def test_partitioning_time_monthly_apply():
6062
"""Tests whether automatically creating new partitions ahead monthly works
6163
as expected."""
@@ -113,6 +115,7 @@ def test_partitioning_time_monthly_apply():
113115
assert table.partitions[13].name == "2020_feb"
114116

115117

118+
@pytest.mark.postgres_version(lt=110000)
116119
def test_partitioning_time_weekly_apply():
117120
"""Tests whether automatically creating new partitions ahead weekly works
118121
as expected."""
@@ -162,6 +165,7 @@ def test_partitioning_time_weekly_apply():
162165
assert table.partitions[6].name == "2019_week_23"
163166

164167

168+
@pytest.mark.postgres_version(lt=110000)
165169
def test_partitioning_time_daily_apply():
166170
"""Tests whether automatically creating new partitions ahead daily works as
167171
expected."""
@@ -211,6 +215,7 @@ def test_partitioning_time_daily_apply():
211215
assert table.partitions[6].name == "2019_jun_04"
212216

213217

218+
@pytest.mark.postgres_version(lt=110000)
214219
def test_partitioning_time_monthly_apply_insert():
215220
"""Tests whether automatically created monthly partitions line up
216221
perfectly."""
@@ -247,6 +252,7 @@ def test_partitioning_time_monthly_apply_insert():
247252
model.objects.create(timestamp=datetime.date(2019, 3, 2))
248253

249254

255+
@pytest.mark.postgres_version(lt=110000)
250256
def test_partitioning_time_weekly_apply_insert():
251257
"""Tests whether automatically created weekly partitions line up
252258
perfectly."""
@@ -287,6 +293,7 @@ def test_partitioning_time_weekly_apply_insert():
287293
model.objects.create(timestamp=datetime.date(2019, 1, 22))
288294

289295

296+
@pytest.mark.postgres_version(lt=110000)
290297
def test_partitioning_time_daily_apply_insert():
291298
"""Tests whether automatically created daily partitions line up
292299
perfectly."""
@@ -326,6 +333,7 @@ def test_partitioning_time_daily_apply_insert():
326333
model.objects.create(timestamp=datetime.date(2019, 1, 10))
327334

328335

336+
@pytest.mark.postgres_version(lt=110000)
329337
@pytest.mark.parametrize(
330338
"kwargs,partition_names",
331339
[
@@ -354,6 +362,7 @@ def test_partitioning_time_multiple(kwargs, partition_names):
354362
assert partition_names == [par.name for par in table.partitions]
355363

356364

365+
@pytest.mark.postgres_version(lt=110000)
357366
@pytest.mark.parametrize(
358367
"kwargs,timepoints",
359368
[
@@ -410,6 +419,7 @@ def test_partitioning_time_delete(kwargs, timepoints):
410419
assert len(table.partitions) == partition_count
411420

412421

422+
@pytest.mark.postgres_version(lt=110000)
413423
def test_partitioning_time_delete_ignore_manual():
414424
"""Tests whether partitions that were created manually are ignored.
415425

tests/test_schema_editor_partitioning.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from .fake_model import define_fake_partitioned_model
1111

1212

13+
@pytest.mark.postgres_version(lt=110000)
1314
def test_schema_editor_create_delete_partitioned_model_range():
1415
"""Tests whether creating a partitioned model and adding a list partition
1516
to it using the :see:PostgresSchemaEditor works."""
@@ -42,6 +43,7 @@ def test_schema_editor_create_delete_partitioned_model_range():
4243
assert len(partitions) == 0
4344

4445

46+
@pytest.mark.postgres_version(lt=110000)
4547
def test_schema_editor_create_delete_partitioned_model_list():
4648
"""Tests whether creating a partitioned model and adding a range partition
4749
to it using the :see:PostgresSchemaEditor works."""
@@ -74,6 +76,7 @@ def test_schema_editor_create_delete_partitioned_model_list():
7476
assert len(partitions) == 0
7577

7678

79+
@pytest.mark.postgres_version(lt=110000)
7780
def test_schema_editor_create_delete_partitioned_model_default():
7881
"""Tests whether creating a partitioned model and adding a default
7982
partition to it using the :see:PostgresSchemaEditor works."""
@@ -106,6 +109,7 @@ def test_schema_editor_create_delete_partitioned_model_default():
106109
assert len(partitions) == 0
107110

108111

112+
@pytest.mark.postgres_version(lt=110000)
109113
def test_schema_editor_create_partitioned_model_no_method():
110114
"""Tests whether its possible to create a partitioned model without
111115
explicitly setting a partitioning method.
@@ -144,6 +148,7 @@ def test_schema_editor_create_partitioned_model_no_key():
144148
schema_editor.create_partitioned_model(model)
145149

146150

151+
@pytest.mark.postgres_version(lt=110000)
147152
def test_schema_editor_add_range_partition():
148153
"""Tests whether adding a range partition works."""
149154

@@ -176,6 +181,7 @@ def test_schema_editor_add_range_partition():
176181
assert len(table.partitions) == 0
177182

178183

184+
@pytest.mark.postgres_version(lt=110000)
179185
def test_schema_editor_add_list_partition():
180186
"""Tests whether adding a list partition works."""
181187

@@ -204,6 +210,7 @@ def test_schema_editor_add_list_partition():
204210
assert len(table.partitions) == 0
205211

206212

213+
@pytest.mark.postgres_version(lt=110000)
207214
@pytest.mark.parametrize(
208215
"method,key",
209216
[

0 commit comments

Comments
 (0)