Skip to content

perf(tests): move SQL worker schema setup to session scope#369

Open
Borda wants to merge 5 commits intomasterfrom
feat/361
Open

perf(tests): move SQL worker schema setup to session scope#369
Borda wants to merge 5 commits intomasterfrom
feat/361

Conversation

@Borda
Copy link
Contributor

@Borda Borda commented Mar 16, 2026

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.

Closes #361

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>
@Borda Borda changed the title perf(tests): move SQL worker schema setup to session scope (#361) perf(tests): move SQL worker schema setup to session scope Mar 16, 2026
@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.94%. Comparing base (5c4f121) to head (f4e0605).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #369   +/-   ##
=======================================
  Coverage   99.94%   99.94%           
=======================================
  Files          12       12           
  Lines        1731     1731           
  Branches      216      216           
=======================================
  Hits         1730     1730           
  Partials        1        1           
Flag Coverage Δ
local 59.21% <ø> (ø)
mongodb 40.67% <ø> (+0.11%) ⬆️
postgres 43.44% <ø> (ø)
redis 46.67% <ø> (ø)
s3 42.46% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5c4f121...f4e0605. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Borda Borda marked this pull request as ready for review March 16, 2026 17:33
@Borda Borda requested a review from shaypal5 as a code owner March 16, 2026 17:33
Copilot AI review requested due to automatic review settings March 16, 2026 17:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.debug during 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize SQL worker schema fixture by moving setup to session scope

2 participants