lmstudio-ai / lmstudio-ai/lmstudio-python

Testing: session scoped fixture for required model loading

Open
#1 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
875
Forks
166
PR merge metrics
No merged PRs in 30d

Description

The `tests/load_models.py`/`tests/unload_models.py` scripts that handle loading and unloading the models used by the test suite currently need to be invoked separately from the test suite execution.

While this approach works, it does mean that you can easily get spurious failures if you forget to run `tox -e load-test-models` before a local testing session.

We could potentially add a session scoped fixture in `conftest.py` to get `pytest` to natively handle ensuring that the required models have been loaded rather than needing to manage it externally: https://stackoverflow.com/questions/76608690/pytest-best-practice-to-setup-and-teardown-before-and-after-all-tests

To avoid pointlessly setting up the models when `-m "not lmstudio"` has been passed, the fixture should scan the loaded modules and ensure the models are only loaded if that mark is present on at least one selected test (see https://docs.pytest.org/en/stable/example/markers.html and https://docs.pytest.org/en/stable/example/special.html)

To make it even more efficient, the `lmstudio` marker could potentially be parameterised with the model IDs that a given test expects to already have loaded. For example:

```python
@pytest.mark.lmstudio(models=[EXPECTED_LLM_ID, EXPECTED_EMBEDDING_ID])
def test_list_downloaded_models_async() -> None:
...
```

When scanning the selected test nodes, the fixture would keep track of the named models, and ensure those models were loaded before running any tests. To avoid problems with unexpected JIT model unloading during the test suite execution, the fixture would still mark models to remain loaded indefinitely.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tests/load_models.py, tests/unload_models.py, and conftest.py, then review the existing tox -e load-test-models workflow and the linked pytest fixture and marker guidance. Implement session-scoped handling that detects selected lmstudio tests, optionally tracks their model IDs, and preserves required models; done means tests no longer require separate model-loading setup and -m "not lmstudio" avoids loading them.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.