test: patch pytest-run-parallel worker context setup#2282
Draft
rwgk wants to merge 1 commit into
Draft
Conversation
Contributor
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Contributor
Author
|
/ok to test |
|
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.
Alternative to #2228 (so we can decide which direction we prefer)
Summary
Add a cuda-python-local workaround for pytest-run-parallel's current fixture-sharing model so CUDA context setup can run inside each worker thread.
The shared helper patches
pytest_run_parallel.plugin.wrap_function_parallelwhen pytest-run-parallel is installed, attaches optional per-worker context factories to selected pytest items, and keeps the behavior a no-op when pytest-run-parallel is absent. The bindings and core test conftests use that helper to set up CUDA context state in the worker thread before the test body runs.Background
pytest-run-parallel executes the same pytest item in multiple worker threads, but fixture values are created by pytest before the worker calls and are shared across those threads. That is problematic for CUDA tests because the current CUDA context is thread-local. Until pytest-run-parallel has an upstream extension hook for per-worker setup, this PR monkeypatches the wrapper function as a localized workaround.
This is intended as an alternative to wrapping CUDA tests directly in each conftest. The monkeypatch centralizes the pytest-run-parallel-specific behavior and keeps package conftests focused on package-specific CUDA setup.
Changes
cuda_python_test_helpers.pytest_run_parallelwith:cuda_bindings/tests/conftest.pyto run per-worker CUDA driver/context setup for CUDA-context-dependent bindings tests.ctxas a no-op to avoid CUDA initialization.cuda_core/tests/conftest.pyto run per-workerinit_cudasetup and replace direct CUDA fixture kwargs that need worker-local values.Notes
This workaround should be removable once pytest-run-parallel exposes an upstream hook that runs inside each worker thread before the test function is invoked.