Skip to content

Consolidate duplicated test scaffolding fixtures across conftests #781

Description

@bencap

Summary

The cascade fixtures setup_lib_db_with_score_set and setup_lib_db_with_variant now exist in two places — tests/lib/conftest.py and the newly added tests/models/conftest.py — as near-verbatim copies. De-duplicate them into a single shared definition so the two copies cannot silently diverge.

Problem

The annotation-pipeline allele refactor introduced tests/models/conftest.py, which copied the existing cascade fixtures from tests/lib/conftest.py. Both copies build the same scaffold on top of the base setup_lib_db (users/licenses):

setup_lib_db (users, licenses)
└─ setup_lib_db_with_score_set → ExperimentSet → Experiment → ScoreSet
└─ setup_lib_db_with_variant → Variant

Having two definitions of the same fixtures means a change to the scaffold (e.g. a new required column on ScoreSet, a relationship change) has to be made in both, and a miss produces tests that pass in one directory and fail — or worse, silently exercise stale state — in the other.

This is the recurring sprawl pattern in the suite: shared scenario setup gets copied into each test directory's conftest.py rather than shared from one location.

Proposed behavior

A single definition of setup_lib_db_with_score_set and setup_lib_db_with_variant is visible to both the tests/lib/ and tests/models/ suites. Pick one of:

  • (a) Lift into the root tests/conftest.py. Fixtures become available everywhere by location. Simplest mechanically.
  • (b) Extract into an importable module under tests/helpers/ (e.g. a fixtures module) that each directory's conftest.py imports. Keeps fixtures organized by what they build.

Tradeoff to settle as part of this issue: the root conftest.py scales badly and has already become a sort of catch-all dumping ground as more shared setup accrues; a tests/helpers/ module keeps things organized but makes fixture discovery an explicit import rather than pytest's location-based magic. Implementing option B would allow us to implement a more manageable fixture directory for our test infrastructure.

Acceptance criteria

  • setup_lib_db_with_score_set and setup_lib_db_with_variant are defined exactly once.
  • The duplicate definitions are removed from tests/models/conftest.py (and from tests/lib/conftest.py if the chosen home is elsewhere).
  • Tests under both tests/lib/ and tests/models/ continue to resolve these fixtures and pass unchanged.
  • No behavioral change to the scaffold the fixtures build (same entities, same field values).

Implementation notes

  • The base setup_lib_db (users/licenses) is the correct dependency root for the consolidated fixtures; do not duplicate that.
  • Scope is deliberately narrow: only de-duplicate the existing cascade fixtures. The broader question of whether DB-backed object setup should move to factories or explicit scenario-builder functions is tracked separately and must not be folded in here.
  • The job_run fixture added in tests/models/conftest.py is local to the annotation-event tests for now; only promote it to the shared home if a second consumer appears.

Metadata

Metadata

Assignees

No one assigned

    Labels

    app: backendTask implementation touches the backendtype: maintenanceMaintaining this projecttype: testsTests for this project

    Type

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions