Skip to content

[RPC] Import tvm.testing lazily in rpc.testing#19658

Merged
tqchen merged 1 commit into
apache:mainfrom
tlopex:rpc-no-pytest-on-import
Jun 2, 2026
Merged

[RPC] Import tvm.testing lazily in rpc.testing#19658
tqchen merged 1 commit into
apache:mainfrom
tlopex:rpc-no-pytest-on-import

Conversation

@tlopex
Copy link
Copy Markdown
Member

@tlopex tlopex commented Jun 2, 2026

Motivation

tvm.testing imports pytest at module load (tvm/testing/utils.py). tvm.rpc.server imports tvm.rpc.testing (to register the rpc.test.* helpers), and tvm.rpc.testing imported tvm.testing at the top level, so a plain import tvm / import tvm.relax pulls pytest in through:

tvm.relax -> tvm.runtime.vm -> tvm.rpc -> rpc.server -> rpc.testing -> tvm.testing -> pytest

As a result pytest is effectively a runtime dependency: a user who installs TVM without pytest hits ModuleNotFoundError: No module named 'pytest' on import. This is easy to miss because test environments install pytest.

Change

tvm.rpc.testing only uses tvm.testing.object_use_count in a single test helper, so import it lazily at the call site instead of at module top level. This keeps the rpc.test.* registration and the helper behavior intact while removing tvm.testing (and pytest) from the import tvm path, so pytest can remain a test-only dependency.

No functional change; rpc.testing is still imported by rpc.server and still registers the same global functions.

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.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 tqchen merged commit a979b2f into apache:main Jun 2, 2026
11 checks passed
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

Successfully merging this pull request may close these issues.

2 participants