Skip to content

Refactor conftest: cell setup in init_database and teardown cleanup #722

@devleo10

Description

@devleo10

Summary

Address the two FIXMEs in backend/tests/conftest.py:

  1. Cell setup in init_database (lines 81–84): Refactor for support of cells (currently commented-out; setup_cells is a separate fixture).
  2. Teardown cleanup (lines 96–104): Enable safe cleanup after tests; currently cannot call db.drop_all() because power/TEROS models use sessions and tests run in a way that leaves the DB in use.

Current behavior

FIXME 1 — Cell setup (lines 81–84)

  • init_database creates tables with db.create_all() but does not create any cells (cell setup is commented out).
  • A separate fixture setup_cells (lines 118–129) creates cell_1 and cell_2 and commits. Tests that need cells use setup_cells; tests that need a clean DB use init_database.
  • The FIXME asks to "refactor later for support of cells" (e.g. unify or document when to use which fixture).

FIXME 2 — Teardown (lines 96–104)

  • After yield test_client, the fixture does not run db.drop_all() (commented out).
  • Reason noted in-code: power and TEROS models use sessions to update data; tests run asynchronously / in parallel, so dropping all tables would affect other tests still using the DB. The FIXME suggests we need to "wait or have the fixture generate all the values" (or otherwise make teardown safe).

Desired behavior

  1. Cell setup: Decide and implement a clear approach — e.g. optionally create default cells in init_database, or document that tests requiring cells must use setup_cells, and remove/update the FIXME.
  2. Teardown: Introduce a teardown strategy that allows safe cleanup (e.g. session scoping, serialization of DB-using tests, or per-test DB state) so that db.drop_all() (or equivalent) can be used where appropriate without breaking other tests.

Location

  • File: backend/tests/conftest.py
  • FIXME 1: lines 81–84 (cell setup in init_database)
  • FIXME 2: lines 96–104 (teardown after yield test_client)

Acceptance criteria

  • FIXME 1: Cell setup strategy is decided and implemented (or FIXME updated/removed with clear documentation).
  • FIXME 2: Teardown strategy is implemented so cleanup is safe (or FIXME updated with current constraints documented).
  • Existing tests still pass; no new test hangs or flakiness from conftest changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions