Repository navigation
Run each test once in the conftest pytest_runtest_call hook - #2174
Open
CriticalRegion wants to merge 1 commit into
Open
CriticalRegion wants to merge 1 commit into
CriticalRegion wants to merge 1 commit into
Conversation
The hook called item.runtest() itself and was not a wrapper, so pytest's own pytest_runtest_call ran the test a second time, without the seed being set again. Make it a wrapper that sets the seed and lets pytest run the test.
This branch has not been deployed
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.
pytest_runtest_callintests/conftest.pycallsitem.runtest()itself, but it is a plain hook implementation.pytest_runtest_callis not a firstresult hook, so pytest's built-in implementation runs afterwards and callsitem.runtest()again. Every test body runs twice, and the second run, the one whose result counts, starts from whatever RNG state the first run left behind instead of the seed.With a test that appends
torch.randn(1)to a module-level list and prints it:This makes the hook a wrapper (
@pytest.hookimpl(wrapper=True)) that sets the seed and yields to pytest's own implementation. The skip for "Torch not compiled with CUDA enabled" / "Found no NVIDIA driver" still works, since the wrapper sees the exception from the yield (checked with a test raising that assertion: it is reported as skipped).Full suite on a DGX Spark (GB10, sm_121, CUDA 13.0, torch 2.14.1+cu130),
pytest tests -n 4:test_matmul_4bit[M1N256K320-fp16-blocksize=64-fp4-compress_statistics={True,False}-has_bias=False-cuda](0.1154 < 0.115), which come from the unseeded second run; with the seed the error is 0.0925. The other 133 were local environment issues (an old default g++ fortorch.compileon CPU, andtorchrunnot on PATH).pre-commit run --all-filespasses.