Repository navigation
Studio tests: compare the hub source restore against the inherited source - #16236
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
The leak this test targets did not happen here. Test 1 sets Suggested fix: record the inherited value inside test 1, before it switches source (for example in a module-level dict that test 2 reads), instead of at import. Alternatively, have test 2 assert |
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Chef's kiss. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
…, not at collection (#16430) ## Summary `(Python 3.13, g-r)` fails on several unrelated PRs (#16413, #16414, #16415): ``` test_hub_source_env_reset_between_tests.py::test_the_next_test_starts_on_the_source_it_inherited E AssertionError: assert 'huggingface' == None E + where 'huggingface' = get('UNSLOTH_STUDIO_HUB_SOURCE') ``` The test reads `_INHERITED = os.environ.get(SOURCE_ENV)` at module import, during collection. Collection goes on after that. Any module collected later that imports the app (for example `tests/test_liveness_reports_*.py` with a module-level `from main import ...`) runs `apply_hub_settings()`, and that always writes `UNSLOTH_STUDIO_HUB_SOURCE`. The conftest fixture `_restore_hub_settings_env` then correctly restores the value each test started with (`huggingface`), but the test compares it against the stale collection-time value (`None`). The fixture is right. The test's baseline is taken too early, and whether it fails depends on which files share the shard. #16236 made it compare against the inherited source, which made it sensitive to this. ## Change The first test records the source env and the "other" source at the moment it starts. That is exactly what the fixture saves and restores. The second test compares against those, and fails with a clear message if it runs without the first one. Nothing else changes. ## Testing - **Repro of the CI failure:** run this file plus a later-collected stand-in module that sets `UNSLOTH_STUDIO_HUB_SOURCE=huggingface` at import, the way the app import does. - main: fails with the same `assert 'huggingface' == None`; - this branch: 3 passed. - This file alone: 2 passed. With `UNSLOTH_STUDIO_HUB_SOURCE=modelscope` in the environment (the case #16236 was for): 2 passed. - Sabotage: with the conftest restore loop disabled, the second test fails again. The test still catches a missing restore.
Problem
tests/test_hub_source_env_reset_between_tests.pychecks that conftest restores the hub source env between tests. Its second test asserts the source is Hugging Face, not the source the process started with. WithUNSLOTH_STUDIO_HUB_SOURCE=modelscopeset in the shell (a developer or CI host that uses the ModelScope mirror), conftest correctly restoresmodelscopeafter the first test, and the second test then fails:Change
Test only. The module reads the inherited source at collection. The first test switches to the other source (ModelScope when Hugging Face was inherited, Hugging Face when ModelScope was), written into
os.environthe way the settings code writes it. The second test asserts the env is back to the inherited value.Tests
UNSLOTH_STUDIO_HUB_SOURCE=modelscope; 2 passed when unset.modelscopeandhuggingface.modelscope,huggingfaceand unset.test_hub_s*.py,test_*modelscope*.py): 139 passed, 2 failed both with and without the ModelScope env. The 2 failures (test_video_untrusted_repo_safetensors_single_file_is_accepted,test_cache_gate_asks_hugging_face_while_modelscope_serves) come fromavanduvicornmissing in the local test env and are unrelated to this change.Not covered
Only run serially. Under
--dist loadgroupthe two tests share the existing xdist group and are unchanged in that respect.