fix: show config errors once at session start instead of per-test#55
Merged
Conversation
- pre-commit section: add args example for Alembic and Django, note on pre-commit autoupdate, update rev from v1.3.0 to v1.2.0 - Remove (v1.3.0) version labels from section headers for unreleased features - Update 'What's new' section to reflect v1.2.0 accurately Closes #35
…d next steps
Three issues fixed:
1. db_url quoting bug: when a user typed a literal URL (e.g. sqlite:///test.db),
it was written as db_url=sqlite:///test.db without quotes — invalid Python.
Now correctly written as db_url="sqlite:///test.db".
2. Confusing default prompt: the old default was the raw Python expression
os.environ.get("TEST_DATABASE_URL", "sqlite:///test.db") which is unclear
for first-time users. Default is now simply sqlite:///test.db with a tip
explaining the env var pattern for CI.
3. Weak next steps: the completion message now shows numbered steps, static
analysis command, and a docs link — so users know exactly what to do next.
Also removes unnecessary 'import os' from generated conftest when a literal
URL is used (os is only imported when the url expr references os.environ).
Before this change, a missing alembic.ini produced the same error message for every collected test (typically 7 times), each with a double traceback due to pytest.fail() being called inside an except block. Changes: - Add pytest_sessionstart hook that validates MRTConfig once and calls pytest.exit() on fatal config errors -- one clear message, no tests run - Break exception chain in mrt fixture (capture error string before calling pytest.fail) to eliminate "During handling of the above exception" noise - Simplify MRTConfigError message in MRTFixture.__init__: Django hint is now only shown via pytest_sessionstart, not duplicated - Update test assertion to match revised error message text
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When
alembic.iniwas missing, pytest-mrt produced the same error forevery collected test. A default project has 7 built-in tests, so the
output was 7 identical blocks each with a double traceback:
(repeated 7 times)
Fix
pytest_sessionstarthook that validatesMRTConfigonce beforeany test runs. Fatal config errors call
pytest.exit()-- one clearmessage, session stops immediately.
mrtfixture by capturing the errorstring before calling
pytest.fail(). This eliminates the "Duringhandling of the above exception" noise.
MRTFixture.__init__error message: the Django hint is nowshown only via
pytest_sessionstart(not duplicated in the fixture).Before / After
Before:
After:
Test plan
431 passed, 17 skipped)test_mrt_fixture_raises_on_missing_alembic_inito match revised messagepytest test_migrations.pywith missing alembic.ini shows one error and exits cleanly