fix: add init_cuda fixture to tests requiring CUDA context #1522
+4
−4
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.
Summary
Four tests in
test_utils.pyrelied on CuPy implicitly creating a CUDA context but failed intermittently whenpytest-randomlyordered them after tests using theinit_cudafixture, which pops the context on cleanup.The affected tests are:
test_view_sliced_externaltest_view_sliced_external_negative_offsettest_view_zero_size_arraytest_struct_arrayRoot Cause
The
init_cudafixture callsDevice().set_current()before a test and pops the context viacuCtxPopCurrent()after the test completes. When a CuPy-based test runs next without its own context setup, CUDA API calls (likecuCtxGetDevice()for zero-sized arrays) fail withCUDA_ERROR_INVALID_CONTEXT.Fix
Add the
init_cudafixture to all four affected tests to ensure a CUDA context is always current.Test Plan
3529696628test_utils.pypass consistently