From b0d1835a73eaf791e72cc4163999cd1033bbf034 Mon Sep 17 00:00:00 2001 From: Roland Tannous Date: Mon, 13 Apr 2026 09:31:21 +0400 Subject: [PATCH] Rename test_studio_run.py -> test_studio_api.py MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The file is entirely about HTTP API endpoint testing (OpenAI-compatible /v1/chat/completions, Anthropic-compatible /v1/messages, API key auth, plus a CLI --help sanity check on the command that runs the API). None of its tests cover training, export, chat-UI, or internal-Python-API concerns. The old name misleadingly suggested "tests for the unsloth studio run CLI subcommand" — the new name reflects the actual scope. Updates: - git mv the file (rename tracked, history preserved) - Rewrite opening docstring to state the API surface focus and call out what is explicitly out of scope - Update all 4 Usage-block path references to the new filename - LOG_FILE renamed to test_studio_api.log - conftest.py fixture import rewritten from test_studio_run to test_studio_api, plus 7 docstring/comment references updated No functional changes to test logic, signatures, or main(). --- studio/backend/tests/conftest.py | 14 ++++++------- ...{test_studio_run.py => test_studio_api.py} | 20 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) rename studio/backend/tests/{test_studio_run.py => test_studio_api.py} (97%) diff --git a/studio/backend/tests/conftest.py b/studio/backend/tests/conftest.py index facb80038b..6aa6d314c1 100644 --- a/studio/backend/tests/conftest.py +++ b/studio/backend/tests/conftest.py @@ -9,7 +9,7 @@ Responsibilities: (and similar flat imports) resolve in test modules — mirrors how the app itself is launched. 2. Provide a hybrid ``studio_server`` session fixture for end-to-end tests - (see ``test_studio_run.py``). The fixture supports two invocation modes: + (see ``test_studio_api.py``). The fixture supports two invocation modes: a. **External server.** If ``UNSLOTH_E2E_BASE_URL`` is set, tests point at an already-running Studio instance. ``UNSLOTH_E2E_API_KEY`` must @@ -24,7 +24,7 @@ Responsibilities: The model / variant for mode (b) come from ``--unsloth-model`` / ``--unsloth-gguf-variant`` pytest options, then ``UNSLOTH_E2E_MODEL`` / ``UNSLOTH_E2E_VARIANT`` env vars, then the defaults in - ``test_studio_run.py``. + ``test_studio_api.py``. """ import os @@ -54,7 +54,7 @@ def pytest_addoption(parser): help = ( "GGUF model id used when starting a server for e2e tests. " "Ignored if UNSLOTH_E2E_BASE_URL is set. Overrides " - "UNSLOTH_E2E_MODEL env var. Defaults to test_studio_run.py's " + "UNSLOTH_E2E_MODEL env var. Defaults to test_studio_api.py's " "DEFAULT_MODEL." ), ) @@ -65,7 +65,7 @@ def pytest_addoption(parser): help = ( "GGUF variant used when starting a server for e2e tests. " "Ignored if UNSLOTH_E2E_BASE_URL is set. Overrides " - "UNSLOTH_E2E_VARIANT env var. Defaults to test_studio_run.py's " + "UNSLOTH_E2E_VARIANT env var. Defaults to test_studio_api.py's " "DEFAULT_VARIANT." ), ) @@ -83,7 +83,7 @@ def studio_server(request): 1. If ``UNSLOTH_E2E_BASE_URL`` is set → point at that server, require ``UNSLOTH_E2E_API_KEY`` alongside (skip if missing). 2. Otherwise → start a fresh ``unsloth studio run`` subprocess via - the existing ``_start_server`` helper in ``test_studio_run.py`` + the existing ``_start_server`` helper in ``test_studio_api.py`` and tear it down on session teardown. Session-scoped so the expensive GGUF load happens at most once per @@ -103,10 +103,10 @@ def studio_server(request): yield external_url, api_key return - # Lazy import: pytest has already loaded test_studio_run into + # Lazy import: pytest has already loaded test_studio_api into # sys.modules by the time any test requests this fixture, so this # is a cache hit, not a re-execution. - import test_studio_run as _e2e + import test_studio_api as _e2e model = ( request.config.getoption("--unsloth-model") diff --git a/studio/backend/tests/test_studio_run.py b/studio/backend/tests/test_studio_api.py similarity index 97% rename from studio/backend/tests/test_studio_run.py rename to studio/backend/tests/test_studio_api.py index dba6adc2fa..9cc17c89fb 100644 --- a/studio/backend/tests/test_studio_run.py +++ b/studio/backend/tests/test_studio_api.py @@ -2,10 +2,11 @@ # Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0 """ -End-to-end tests for ``unsloth studio run`` and API key authentication. +End-to-end tests for Unsloth Studio's HTTP API surface. -Exercises the usage examples shown on the API Keys page plus the Anthropic -Messages API: +Covers the OpenAI-compatible and Anthropic-compatible endpoints exposed +by the server that ``unsloth studio run`` boots, plus API key +authentication and the CLI's ``--help`` output: 1. curl -- basic chat completions (non-streaming) 2. curl -- streaming chat completions @@ -16,24 +17,25 @@ Messages API: 7. Anthropic Python SDK -- non-streaming 8. Anthropic Messages API -- streaming with tools -The test also validates the ``--help`` output and the server banner. +Training, export, fine-tuning, and chat-UI concerns are out of scope — +see the unit suites elsewhere under ``studio/backend/tests/`` for those. Usage: # Script mode — launches its own server via ``unsloth studio run``. - python tests/test_studio_run.py - python tests/test_studio_run.py --model unsloth/... --gguf-variant ... + python tests/test_studio_api.py + python tests/test_studio_api.py --model unsloth/... --gguf-variant ... # Pytest mode, external server — start a Studio server yourself, # then point pytest at it. Fastest iteration loop. unsloth studio run --model unsloth/Qwen3-1.7B-GGUF --gguf-variant UD-Q4_K_XL & export UNSLOTH_E2E_BASE_URL=http://127.0.0.1:8080 export UNSLOTH_E2E_API_KEY=sk-unsloth-... # from the server banner - pytest tests/test_studio_run.py -v + pytest tests/test_studio_api.py -v # Pytest mode, fixture-managed server — pytest launches and tears # down the server itself. One-shot verification, CI-friendly. - pytest tests/test_studio_run.py -v \\ + pytest tests/test_studio_api.py -v \\ --unsloth-model unsloth/Qwen3-1.7B-GGUF \\ --unsloth-gguf-variant UD-Q4_K_XL @@ -68,7 +70,7 @@ STARTUP_TIMEOUT = 120 # seconds to wait for banner LOG_FILE = ( Path(__file__).resolve().parent.parent.parent.parent / "temp" - / "test_studio_run.log" + / "test_studio_api.log" )