-
Notifications
You must be signed in to change notification settings - Fork 3
ci: run backend tests against Postgres, not only in-memory SQLite #154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
+67
−2
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| [pytest] | ||
| # Explicit + pinned pytest-asyncio config (see conftest.py for fixture setup). | ||
| # | ||
| # asyncio_default_fixture_loop_scope / asyncio_default_test_loop_scope = | ||
| # "session" gives the whole test session ONE event loop instead of a fresh | ||
| # one per test (the pytest-asyncio 1.x default is "function"). This matters | ||
| # because db.py's `engine` (the SQLAlchemy async engine / connection pool) | ||
| # is created once at import time. Against SQLite/aiosqlite that mismatch is | ||
| # silently tolerated, but asyncpg's connections are strictly bound to the | ||
| # event loop that created them — reusing the pooled engine from a second, | ||
| # different per-test event loop raises | ||
| # "got Future <Future ...> attached to a different loop". Pinning both | ||
| # scopes to "session" keeps the engine and every test on the same loop, so | ||
| # the suite runs unchanged against Postgres in CI (see | ||
| # .github/workflows/ci.yml) as well as the SQLite default. | ||
| asyncio_mode = strict | ||
| asyncio_default_fixture_loop_scope = session | ||
| asyncio_default_test_loop_scope = session |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| """Regression test for conftest.py's DATABASE_URL handling. | ||
|
|
||
| The setup_db fixture drops all tables after every test, so the suite must | ||
| never run against an ambient DATABASE_URL from a developer's shell (which | ||
| could point at a real dev/prod database). conftest.py must force in-memory | ||
| SQLite unless the explicit TEST_DATABASE_URL opt-in is set (as CI does for | ||
| its Postgres service container). | ||
| """ | ||
|
|
||
| import os | ||
|
|
||
|
|
||
| def test_database_url_is_test_url_or_sqlite(): | ||
| """After conftest import, DATABASE_URL is either the explicit | ||
| TEST_DATABASE_URL opt-in or the in-memory SQLite default — never an | ||
| ambient value inherited from the shell.""" | ||
| expected = os.environ.get("TEST_DATABASE_URL") or "sqlite+aiosqlite://" | ||
| assert os.environ["DATABASE_URL"] == expected |
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.
Uh oh!
There was an error while loading. Please reload this page.