Skip to content

Use conftest.py for shared fixtures #516

Description

@contsili

Our tests currently rely on __init__.py files so that shared fixtures can be imported explicitly, e.g. from test.fixtures.<module> import .... This makes test/ an importable package.

scientific-python recommends against putting __init__.py in the tests directory (as it can confuse package-discovery), and share fixtures through conftest.py instead, which pytest auto-discovers so no import is needed (yay!). See https://learn.scientific-python.org/development/guides/pytest/

Note: conftest.py only auto-shares @pytest.fixture-decorated objects. Plain helper functions, stub model classes, and constants currently living in the fixture modules are not auto-imported.

Proposed change

  1. Remove __init__.py from the test directories.
  2. Move shared fixtures into conftest.py files, scoped by location:
    • Fixtures used across all tests → top-level test/conftest.py.
    • Fixtures specific to a subtree → a local conftest.py, e.g. test/test_longitudinal/conftest.py.
  3. Replace explicit fixture imports (from test.fixtures... import ...) with fixtures injected by argument name.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status
    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions