Conversation
Schema creation (CREATE SCHEMA IF NOT EXISTS + engine lifecycle) now runs once per xdist worker session via a new `worker_sql_connection` session-scoped fixture, eliminating one DB roundtrip per SQL test in parallel runs. `inject_worker_schema_for_sql_tests` retains function scope for the cheap per-test monkeypatching of SQLALCHEMY_DATABASE_URL and SQL_CONN_STR. Also fixes `str | None` return annotations to `Optional[str]` for Python 3.9 compatibility. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #369 +/- ##
=======================================
Coverage 99.94% 99.94%
=======================================
Files 12 12
Lines 1731 1731
Branches 216 216
=======================================
Hits 1730 1730
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
…ema_name` and `_build_worker_url`
…uild_worker_url` unit tests
There was a problem hiding this comment.
Pull request overview
This PR refactors the SQL-test xdist schema-isolation logic in tests/conftest.py by extracting URL/schema helpers, introducing a session-scoped schema-creation fixture, and adding focused unit tests for the helpers.
Changes:
- Add
_build_worker_url()and unit tests covering worker schema naming and URL option handling. - Introduce
worker_sql_connection(session-scoped) to create the per-worker PostgreSQL schema once, and simplify per-test monkeypatching. - Minor logging improvement (parameterized
logger.debugduring cleanup).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| tests/conftest.py | Extracts URL-building logic, adds a session fixture to create worker schemas once, and updates the autouse SQL schema injection fixture to reuse it. |
| tests/test_conftest_helpers.py | Adds unit tests for the new private helpers (_worker_schema_name, _build_worker_url). |
You can also share your feedback on Copilot code review. Take the survey.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Schema creation (CREATE SCHEMA IF NOT EXISTS + engine lifecycle) now runs once per xdist worker session via a new
worker_sql_connectionsession-scoped fixture, eliminating one DB roundtrip per SQL test in parallel runs.inject_worker_schema_for_sql_testsretains function scope for the cheap per-test monkeypatching of SQLALCHEMY_DATABASE_URL and SQL_CONN_STR.Closes #361