lmstudio-ai / lmstudio-ai/lmstudio-python
Testing: session scoped fixture for required model loading
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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