Skip to content

Optimize SQL worker schema fixture by moving setup to session scope #361

@shaypal5

Description

@shaypal5

Summary

The inject_worker_schema_for_sql_tests autouse fixture in tests/conftest.py currently runs at function scope for SQL tests. In xdist runs, this repeats schema setup and URL patching work for every SQL test case.

Current behavior

  • For each SQL test item, the fixture:
    • reads/parses SQLALCHEMY_DATABASE_URL
    • rewrites connection options for search_path
    • monkeypatches environment/module constants
    • attempts schema creation
  • This is functionally correct, but adds repeated overhead in parallel test runs.

Proposed change

Refactor SQL worker isolation into:

  • a session-scoped worker fixture that creates and validates worker schema once and prepares worker-specific connection settings.
  • lightweight function-scoped hooks only where per-test behavior is necessary.

Acceptance criteria

  • SQL tests still pass in both serial and xdist modes.
  • Worker schema is created once per worker process.
  • Existing schema cleanup behavior remains correct.
  • No regressions in SQL test isolation semantics.

Context

Follow-up from Copilot review discussion on PR #360.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions