Skip to content

test: patch pytest-run-parallel worker context setup#2282

Draft
rwgk wants to merge 1 commit into
NVIDIA:mainfrom
rwgk:pytest-run-parallel_patched_wrap_function_parallel
Draft

test: patch pytest-run-parallel worker context setup#2282
rwgk wants to merge 1 commit into
NVIDIA:mainfrom
rwgk:pytest-run-parallel_patched_wrap_function_parallel

Conversation

@rwgk

@rwgk rwgk commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

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_parallel when 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

  • Add cuda_python_test_helpers.pytest_run_parallel with:
    • idempotent installation of the pytest-run-parallel wrapper patch
    • signature validation for the upstream wrapper entry point
    • isolated kwargs copies for worker and iteration calls
    • per-worker context factory support attached to pytest item functions
    • no-op behavior when pytest-run-parallel is not importable
  • Wire cuda_bindings/tests/conftest.py to run per-worker CUDA driver/context setup for CUDA-context-dependent bindings tests.
  • Exclude cuDLA tests from the bindings worker-context selection because they intentionally override ctx as a no-op to avoid CUDA initialization.
  • Wire cuda_core/tests/conftest.py to run per-worker init_cuda setup and replace direct CUDA fixture kwargs that need worker-local values.
  • Add unit coverage using a fake pytest-run-parallel module so the monkeypatch mechanics can be tested without requiring pytest-run-parallel or CUDA hardware.

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.

@rwgk rwgk added this to the cuda.core v1.1.0 milestone Jun 30, 2026
@rwgk rwgk self-assigned this Jun 30, 2026
@rwgk rwgk added P1 Medium priority - Should do test Improvements or additions to tests cuda.bindings Everything related to the cuda.bindings module cuda.core Everything related to the cuda.core module labels Jun 30, 2026
@copy-pr-bot

copy-pr-bot Bot commented Jun 30, 2026

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

@github-actions github-actions Bot added the CI/CD CI/CD infrastructure label Jun 30, 2026
@rwgk

rwgk commented Jun 30, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test

@github-actions

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI/CD CI/CD infrastructure cuda.bindings Everything related to the cuda.bindings module cuda.core Everything related to the cuda.core module P1 Medium priority - Should do test Improvements or additions to tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant