Repository navigation
test(executorch): keep the sys.modules leak checks honest under PYTEST_ADDOPTS - #4918
Closed
shoumikhin wants to merge 1 commit into
Closed
shoumikhin wants to merge 1 commit into
shoumikhin wants to merge 1 commit into
Conversation
…T_ADDOPTS Two tests run another test in a child pytest process and then check that it left no copy of torch_tensorrt_executorch_runtime in sys.modules. The child inherited PYTEST_ADDOPTS. With "-n 2" in it, the inner test ran in an xdist worker, so the child's own sys.modules never held the module and both checks passed even with the leak fixes removed. "-o addopts=" clears only the ini value, not the variable. Run the child without PYTEST_ADDOPTS, give it a timeout so a hung child fails the test instead of the whole job, and make a failure say which of the two things went wrong.
shoumikhin
force-pushed
the
executorch-leak-guard-env
branch
from
October 22, 2026 19:11
94773eb to
aca7075
Compare
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.
What is wrong today
Two tests check that another test leaves no copy of
torch_tensorrt_executorch_runtimeinsys.modules, since a later test in the same process would import that copy instead of the real package. Each one runs the other test in a child pytest process and then looks at the child'ssys.modules:test_the_example_loader_test_leaves_no_stand_in_behindtest_the_shim_test_leaves_no_delegate_module_behindThe child inherits
PYTEST_ADDOPTS. If it contains-n 2, pytest-xdist runs the inner test in a separate worker process. The child's ownsys.modulesnever gets the module, so both checks pass even when the leak is back. The-o addopts=flag does not help, because it clears only the ini setting, not the environment variable.When the checks do fail, the output says only "1 passed" next to
assert 1 == 0, which does not say what went wrong.What this change does
PYTEST_ADDOPTS.sys.modules.What was tested
On Linux x86-64 with the pinned ExecuTorch nightly, with the two leak fixes from #4848 removed on purpose:
PYTEST_ADDOPTSunsetPYTEST_ADDOPTS="-n 2"With the leak fixes in place, both checks pass either way, and
test_python_runtime.pyplustest_shared_runtime_workflow.pygive 104 passed, the same as on main.