Skip to content

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

Merged
shaypal5 merged 5 commits into
masterfrom
feat/361
Mar 20, 2026
Merged

perf(tests): move SQL worker schema setup to session scope#369
shaypal5 merged 5 commits into
masterfrom
feat/361

Conversation

@Borda

@Borda Borda commented Mar 16, 2026

Copy link
Copy Markdown
Contributor

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

@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

codecov Bot commented Mar 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.94%. Comparing base (7523386) to head (64a0b71).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #369   +/-   ##
=======================================
  Coverage   99.94%   99.94%           
=======================================
  Files          12       12           
  Lines        1735     1735           
  Branches      218      218           
=======================================
  Hits         1734     1734           
  Partials        1        1           
Flag Coverage Δ
local 59.30% <ø> (ø)
mongodb 40.69% <ø> (ø)
postgres 43.40% <ø> (ø)
redis 46.80% <ø> (ø)
s3 42.47% <ø> (ø)

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 7523386...64a0b71. 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

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread tests/conftest.py
Comment thread tests/test_conftest_helpers.py Outdated
Comment thread tests/conftest.py
Borda and others added 5 commits March 20, 2026 13:11
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>
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

area: sql SQL/PostgreSQL backend or SQLAlchemy integration. area: tests Test suite, fixtures, coverage, or local test scripts. enhancement impact: performance Performance, scalability, or benchmark impact. outcome: merged Merged into the repository. size: small Small PR by changed-file count. source: human Opened directly by a human contributor. type: feature Adds or materially changes user-facing functionality. type: perf Performance optimization or benchmark-driven change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize SQL worker schema fixture by moving setup to session scope

3 participants