Skip to content

Commit 58a5596

Browse files
nanotaboadaclaude
andcommitted
test(migrations): add SQLite guard, move assertions before upgrade restore (#2)
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent ec97c95 commit 58a5596

2 files changed

Lines changed: 18 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ This project uses famous football coaches as release codenames, following an A-Z
5757
before any workers are forked, replacing the entrypoint-driven migration
5858
pattern (#2)
5959
- `tests/test_migrations.py`: integration tests for migration downgrade paths —
60-
verifies each step removes only its seeded rows and restores correctly (#2)
60+
verifies each step removes only its seeded rows and restores correctly; guarded
61+
with `pytestmark` skip for non-SQLite databases; assertions moved before
62+
`upgrade head` restore step for clarity (#2)
6163
- `tests/conftest.py`: session-scoped `apply_migrations` fixture runs
6264
`alembic upgrade head` once before the test session, ensuring the database
6365
exists and is at head in CI and local environments (#2)

tests/test_migrations.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,24 @@
99
or more steps, asserts the expected state, then restores to head before the
1010
next test, ensuring the shared SQLite database remains consistent for any
1111
subsequent test runs.
12+
13+
These tests are SQLite-only: they open the database file directly via
14+
sqlite3.connect() to inspect raw state, which is not possible with PostgreSQL.
1215
"""
1316

1417
import sqlite3
1518

19+
import pytest
1620
from alembic import command
1721

1822
from databases.player_database import DATABASE_URL
1923
from tests.conftest import ALEMBIC_CONFIG
2024

25+
pytestmark = pytest.mark.skipif(
26+
not DATABASE_URL.startswith("sqlite"),
27+
reason="Migration downgrade tests require SQLite",
28+
)
29+
2130
DB_PATH = DATABASE_URL.replace("sqlite+aiosqlite:///", "")
2231

2332

@@ -30,11 +39,11 @@ def test_migration_downgrade_003_removes_substitutes_only():
3039
subs = conn.execute("SELECT COUNT(*) FROM players WHERE starting11=0").fetchone()[0]
3140
conn.close()
3241

33-
command.upgrade(ALEMBIC_CONFIG, "head")
34-
3542
assert total == 11
3643
assert subs == 0
3744

45+
command.upgrade(ALEMBIC_CONFIG, "head")
46+
3847

3948
def test_migration_downgrade_002_removes_starting11_only():
4049
"""Downgrade 002→001 removes the 11 seeded Starting XI, leaves table empty."""
@@ -44,10 +53,10 @@ def test_migration_downgrade_002_removes_starting11_only():
4453
total = conn.execute("SELECT COUNT(*) FROM players").fetchone()[0]
4554
conn.close()
4655

47-
command.upgrade(ALEMBIC_CONFIG, "head")
48-
4956
assert total == 0
5057

58+
command.upgrade(ALEMBIC_CONFIG, "head")
59+
5160

5261
def test_migration_downgrade_001_drops_players_table():
5362
"""Downgrade 001→base drops the players table entirely."""
@@ -59,6 +68,6 @@ def test_migration_downgrade_001_drops_players_table():
5968
).fetchone()
6069
conn.close()
6170

62-
command.upgrade(ALEMBIC_CONFIG, "head")
63-
6471
assert table is None
72+
73+
command.upgrade(ALEMBIC_CONFIG, "head")

0 commit comments

Comments
 (0)