Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing: session scoped fixture for required model loading #1

Open
ncoghlan opened this issue Feb 17, 2025 · 0 comments
Open

Testing: session scoped fixture for required model loading #1

ncoghlan opened this issue Feb 17, 2025 · 0 comments

Comments

@ncoghlan
Copy link
Collaborator

ncoghlan commented Feb 17, 2025

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:

@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.

@ncoghlan ncoghlan changed the title Testing: switch setup/teardown to session scoped fixture Testing: session scoped fixture for required model loading Feb 18, 2025
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

No branches or pull requests

1 participant