Skip to content

test: make menubar imports safe in headless environments#349

Closed
lyonsno wants to merge 2 commits intojundot:mainfrom
lyonsno:fix/omlx-app-import-safety-main
Closed

test: make menubar imports safe in headless environments#349
lyonsno wants to merge 2 commits intojundot:mainfrom
lyonsno:fix/omlx-app-import-safety-main

Conversation

@lyonsno
Copy link
Copy Markdown
Contributor

@lyonsno lyonsno commented Mar 22, 2026

Summary

This PR decouples packaging/omlx_app imports from the heavy omlx runtime so menubar-focused tests can run in headless/CI environments without initializing MLX/Metal during test collection.

Previously, importing omlx_app (or modules under it) could import omlx._version, which triggers omlx/init.py side effects and can abort when MLX initializes in non-GUI/headless contexts.

What Changed

  1. packaging/omlx_app/init.py
  • Replaced direct from omlx._version import version with a lightweight loader that reads omlx/_version.py via
    importlib.util without importing omlx.
  1. packaging/omlx_app/app.py
  • Switched version import from from omlx._version import version to from . import version so it uses the
    package-local safe loader.
  1. tests/conftest.py
  • Made omlx.request imports lazy in fixtures (sample_request, sample_request_factory) and used TYPE_CHECKING for annotations, preventing eager MLX import at pytest collection time.
  1. tests/test_omlx_app_package_init.py (new)
  • Added guard tests ensuring:
    • importing omlx_app does not import omlx* runtime modules
    • importing omlx_app.app (with GUI deps stubbed) does not import omlx* runtime modules

Why

  • Keeps menubar app modules importable in environments where MLX/Metal runtime initialization is unavailable or unsafe during test discovery.
  • Prevents collection-time crashes and makes menubar/server-manager tests reliable in CI/headless execution.

Behavioral Impact

  • No intended runtime behavior change for the app itself.
  • Version string resolution remains sourced from omlx/_version.py; fallback is "0.0.0" only if that file/spec cannot be loaded.

Tests

  1. /Users/noahlyons/dev/omlx/.venv/bin/python -m pytest tests/test_omlx_app_package_init.py tests/test_omlx_app.py -q
  2. Result: 80 passed

Risk / Notes

  1. Low risk: changes are import-path and test-harness focused.
  2. The only functional code path touched in app runtime is version import plumbing.

@jundot jundot force-pushed the main branch 8 times, most recently from 65b4ef1 to 2e39d71 Compare March 28, 2026 01:20
@jundot
Copy link
Copy Markdown
Owner

jundot commented Mar 29, 2026

Closing this since #350 already includes all changes from this PR (import safety, conftest lazy imports, test_omlx_app_package_init.py). No need to merge both.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants