[fix] Replace pytest.skip with requirement_not_met in conjugateGradientMultiBlockCG example (#1530)#1861
Conversation
…tMultiBlockCG example The example imported pytest inside main() and used pytest.skip() for requirement checks, which is inappropriate for a standalone script. All other cuda.bindings examples use requirement_not_met() from _example_helpers for this purpose. Replace all pytest.skip() calls with requirement_not_met() and remove the local pytest import, aligning this example with the established pattern used across the rest of the examples directory. Fixes NVIDIA#1530 Relates to NVIDIA#1839 Signed-off-by: Eden <edenfunf@users.noreply.github.com>
|
Hi, could someone help review and trigger CI for this PR? Thanks! |
|
Sorry we cannot take PRs against cuda-bindings, which has |
Thanks for the clarification! Got it — I didn’t realize that cuda-bindings is not open for external contributions due to the license. Appreciate the explanation. I’ll focus on cuda-core / cuda-pathfinder or other open components instead. Thanks again! |
What
Replace all
pytest.skip()calls withrequirement_not_met()incuda_bindings/examples/4_CUDA_Libraries/conjugateGradientMultiBlockCG_test.py,and remove the
import pytestthat was placed insidemain().Before:
After:
Why
Issue #1530 tracks that pytest must not be imported in standalone examples.
After auditing all examples in
cuda_bindings/examples/, this is the onlyfile that still imports pytest. Every other example already uses
requirement_not_met()fromcuda.bindings._example_helpersto signalunsupported configurations and exit cleanly via
sys.exit.Using
pytest.skip()in a standalone script is incorrect — it raisespytest.skip.Exceptionwhich is only meaningful when running under a pytesttest session. Outside of pytest, the exception propagates uncaught.
How
requirement_not_metto the_example_helpersimport at the top ofthe file (it is already exported from
cuda.bindings._example_helpers.__all__).import pyteststatement that was placed insidemain().returnwaive (for the known NVRTC issue) with aproper
requirement_not_met()call that prints a message to stderr andexits with a non-zero code (or zero if
CUDA_BINDINGS_SKIP_EXAMPLE=0).pytest.skip(...)calls withrequirement_not_met(...),matching the pattern used in every other example file.
Test
ruff checkandruff format --checkpass on the modified file.pre-commit run --files cuda_bindings/examples/4_CUDA_Libraries/conjugateGradientMultiBlockCG_test.pypasses all hooks (ruff, SPDX headers, end-of-file, trailing whitespace, etc.).
pytest(verified with grep).just now through the standard
requirement_not_met()path instead ofa silent
return.Fixes #1530
Relates to #1839