Stop _gl_context from converting test failures into skips - #2565
Open
LeSingh1 wants to merge 1 commit into
Open
Conversation
_gl_context() yields from inside a try whose handler turns everything into a
skip:
try:
...create context and texture...
yield int(tex_id.value), int(target)
except Exception as e:
# Convert any pyglet/GL creation failure into a clean skip
pytest.skip(f"Could not create GL context/texture: {type(e).__name__}: {e}")
@contextmanager re-raises the with-body's exception at the yield point, so
`except Exception` also catches failures from the test body. AssertionError
is an Exception; pytest's Skipped is a BaseException, so the replacement
skip escapes cleanly and the run is reported as SKIPPED.
That means neither assertion in test_cuda_gl_register_image_smoketest can
fail the suite:
assert name in acceptable, f"cudaGraphicsGLRegisterImage returned {name}"
assert int(resource) != 0
A genuinely wrong cudaGraphicsGLRegisterImage return is reported as
"Could not create GL context/texture: AssertionError: ...". The comment on
the handler says "creation failure", which is what it was meant to cover.
Move the context/texture creation into _create_gl_texture() so the handler
wraps only that, and keep the yield outside it. Cleanup stays in the outer
finally, so a partially built context is still torn down. tex_id is now
initialized, which also removes an UnboundLocalError that the finally block
was silently swallowing when creation failed early.
Adds test_gl_context_lets_body_failures_fail, which stubs
_create_gl_texture() and asserts an AssertionError raised in the with-body
propagates. It needs no GL context, no display and no GPU.
Contributor
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.
_gl_context()yields from inside atrywhose handler turns everything into a skip:@contextmanagerre-raises the with-body's exception at the yield point, soexcept Exceptionalso catches failures from the test body.AssertionErroris anException; pytest'sSkippedis aBaseException, so the replacement skip escapescleanly and the run is reported as SKIPPED.
That means neither assertion in
test_cuda_gl_register_image_smoketestcan fail the suite:A genuinely wrong
cudaGraphicsGLRegisterImagereturn is reported asCould not create GL context/texture: AssertionError: .... The handler's own comment says"creation failure", which is what it was meant to cover.
Demonstrated with a minimal standalone reproduction of the same shape:
Both tests in this module are on the always-skipped list in #2077, so this has never been
visible in CI.
Fix
Move the context/texture creation into
_create_gl_texture()so the handler wraps onlythat, and keep the
yieldoutside it. Cleanup stays in the outerfinally, so apartially built context is still torn down on the skip path.
tex_idis now initialized,which also removes an
UnboundLocalErrorthat thefinallyblock was silently swallowingwhen creation failed before the texture existed.
pytest.importorskipand the no-EGLpytest.skipinside_create_gl_texturestillpropagate correctly —
Skippedis aBaseException, soexcept Exceptiondoes not catchthem.
Test
test_gl_context_lets_body_failures_failstubs_create_gl_texture()and asserts that anAssertionErrorraised inside thewithbody propagates. No GL context, no display, noGPU, no pyglet — so unlike the two smoketests it actually runs in CI. I verified it
passes against the restructured contextmanager and that the pre-existing shape converts
the same failure into a skip.
ruff checkandruff format --checkare clean.