[RPC] Import tvm.testing lazily in rpc.testing#19658
Merged
Merged
Conversation
tvm.testing imports pytest at module load (tvm/testing/utils.py). rpc.server
imports rpc.testing to register the rpc.test.* helpers, and rpc.testing imported
tvm.testing at the top level, so a plain `import tvm` / `import tvm.relax` pulled
pytest in through:
tvm.relax -> tvm.runtime.vm -> tvm.rpc -> rpc.server -> rpc.testing
-> tvm.testing -> pytest
That makes pytest a de-facto runtime dependency: installing TVM without pytest
fails with `ModuleNotFoundError: No module named 'pytest'` on import.
rpc.testing only uses tvm.testing.object_use_count in a single test helper, so
import it lazily at the call site. This keeps the rpc.test.* registration and the
helper working while removing tvm.testing (and pytest) from the `import tvm` path,
so pytest can stay a test-only dependency.
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors python/tvm/rpc/testing.py to lazily import tvm.testing inside the ref_count block instead of at the top level. This prevents importing pytest (via tvm.testing) during a standard import tvm path when rpc.server registers its helpers. There are no review comments, so no additional feedback is provided.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
tqchen
approved these changes
Jun 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
tvm.testingimportspytestat module load (tvm/testing/utils.py).tvm.rpc.serverimportstvm.rpc.testing(to register therpc.test.*helpers), andtvm.rpc.testingimportedtvm.testingat the top level, so a plainimport tvm/import tvm.relaxpullspytestin through:As a result
pytestis effectively a runtime dependency: a user who installs TVM withoutpytesthitsModuleNotFoundError: No module named 'pytest'on import. This is easy to miss because test environments installpytest.Change
tvm.rpc.testingonly usestvm.testing.object_use_countin a single test helper, so import it lazily at the call site instead of at module top level. This keeps therpc.test.*registration and the helper behavior intact while removingtvm.testing(andpytest) from theimport tvmpath, sopytestcan remain a test-only dependency.No functional change;
rpc.testingis still imported byrpc.serverand still registers the same global functions.