Skip to content

Commit 6b867b5

Browse files
authored
fix: move hardcoded model name to config and unify error handling (#22)
- Extract DEFAULT_EXPLAIN_MODEL constant to config.py; add MRTConfig.explain_model field so callers can override the model without touching cli.py - Replace FileNotFoundError in MRTFixture with pytest.fail() so missing alembic.ini surfaces as a clean test failure instead of an unexpected exception type in a pytest fixture context - Update test to match new pytest.fail.Exception behaviour
1 parent fafc90a commit 6b867b5

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

pytest_mrt/cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
from . import __version__
1111
from .adapters.django_detector import analyze_django_migrations, is_django_migration
12+
from .config import DEFAULT_EXPLAIN_MODEL
1213
from .core.detector import analyze_migrations
1314

1415
app = typer.Typer(
@@ -411,7 +412,7 @@ def explain(
411412
try:
412413
client = anthropic.Anthropic()
413414
message = client.messages.create(
414-
model="claude-opus-4-5",
415+
model=DEFAULT_EXPLAIN_MODEL,
415416
max_tokens=1024,
416417
messages=[
417418
{

pytest_mrt/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
if TYPE_CHECKING:
77
pass
88

9+
# Default model for `mrt explain`. Override via MRTConfig(explain_model=...).
10+
DEFAULT_EXPLAIN_MODEL = "claude-opus-4-5"
11+
912

1013
@dataclass
1114
class MRTConfig:
@@ -69,3 +72,7 @@ class MRTConfig:
6972
# Path to the Django project root. Added to sys.path before import.
7073
# Required if the project is not on the Python path already.
7174
django_project_dir: str | None = None
75+
76+
# Model used by `mrt explain`. Defaults to DEFAULT_EXPLAIN_MODEL.
77+
# Override to use a different Claude model, e.g. "claude-3-5-haiku-latest".
78+
explain_model: str = DEFAULT_EXPLAIN_MODEL

pytest_mrt/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def __init__(self, config: MRTConfig):
8989
" )\n\n"
9090
" See: https://croc100.github.io/pytest-mrt/quickstart/#django"
9191
)
92-
raise FileNotFoundError(_hint)
92+
pytest.fail(_hint, pytrace=False)
9393

9494
self._runner = MigrationRunner(config.alembic_ini, config.db_url)
9595
self._seeder = SmartSeeder(self._runner.engine)

tests/test_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,11 +614,11 @@ def test_auto_detect_django_no_switch_when_explicit_django_settings(tmp_path, mo
614614
# ── MRTFixture missing alembic.ini ─────────────────────────────────────
615615

616616
def test_mrt_fixture_raises_on_missing_alembic_ini(tmp_path, monkeypatch):
617-
"""MRTFixture raises FileNotFoundError with Django hint when alembic.ini missing."""
617+
"""MRTFixture calls pytest.fail with a Django hint when alembic.ini is missing."""
618618
monkeypatch.delenv("DJANGO_SETTINGS_MODULE", raising=False)
619619

620620
cfg = MRTConfig(alembic_ini=str(tmp_path / "nonexistent.ini"), db_url="sqlite:///test.db")
621-
with pytest.raises(FileNotFoundError, match="django_settings"):
621+
with pytest.raises(pytest.fail.Exception, match="django_settings"):
622622
MRTFixture(cfg)
623623

624624

0 commit comments

Comments
 (0)