Repository navigation
Clean up warnings in the test suite - #2917
Merged
Merged
Conversation
The test suite printed 240 warnings. All are gone: - Run examples and tutorials with runpy.run_path(run_name="__main__") instead of SourceFileLoader.load_module(), which Python 3.15 removes. The old code also ran each file twice, since load_module() already executes the module before exec_module() ran it again. - Pass lists, not generators, to parametrize (deprecated in pytest). - Ignore draw_text's PerformanceWarning in the tests and examples that use draw_text on purpose. - Fix the OpenGL __del__ methods raising AttributeError when creating the object failed before the OpenGL handle was set, for example a texture with 5 components. Seven classes had the same pattern. - test_container_size_zero now checks for its "Container size is 0" warning, and test_works_in_box_layout gives its layout a size. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-warnings # Conflicts: # CHANGELOG.md
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.
Summary
The test suite printed 240 warnings; it now prints none. Every group from the CI warnings summary is handled:
PytestRemovedIn10Warning: non-Collection iterable passed to parametrizetest_examples.pyandtest_tutorials.pypassed generatorslist(...)DeprecationWarning:load_module()(230 of them)SourceFileLoader(...).load_module(), which Python 3.15 removesrunpy.run_path(path, run_name="__main__")PerformanceWarning: draw_text is slowdraw_texton purposePerformanceWarning(only those tests, not the whole suite)PytestUnraisableExceptionWarning:AttributeError: ... no attribute '_glo'__del__methodsUserWarning: Container size is 0test_container_size_zerotests that case on purpose;test_works_in_box_layouthad a layout with no sizepytest.warns; the second gives its layout a size, like the anchor-layout test next to itExamples and tutorials ran twice
loader.exec_module(loader.load_module())ran each file twice:load_module()already executes the module, and thenexec_module()ran it again. A throwaway file confirmed it executed 2 times.runpy.run_pathruns it once, aspython -mwould, so the integration tests take 22.5 s instead of 26.4 s here. All 233 integration tests still pass.OpenGL objects whose creation failed
The shared base classes (for example
Framebuffer.__init__) validate their arguments and can raise before the OpenGL class sets its handle (_glo). Python still runs__del__on the half-built object, and__del__readself._glo, which printed "Exception ignored in__del__... AttributeError". Users whose texture or framebuffer creation fails see that too, not just the tests.Seven classes had the pattern: buffer, compute shader, framebuffer, program, texture, texture array and vertex array. Each
__del__now returns early if the handle was never set.OpenGLVertexArraystores its handle as the slotglo, not_glo, so its guard checks that.Tests
New
test_failed_creation_collected_quietly(tests/unit/gl/test_gl_gc.py): in bothautoandcontext_gcmodes, it makes texture and framebuffer creation fail and garbage-collects. It then checks that no unraisable errors were reported, usingsys.unraisablehook. Ondevelopmentit reports the 3AttributeErrors.Normal cleanup still works: the existing
test_context_gcchecks that normally created objects are still cleaned up. Using_glofor the vertex array's guard, the mistake I first made, makes that test fail, so the guards can't silently break cleanup.Full suite on pyglet 3.0.dev11:
The 3 failures are the same render tests that only fail on my machine, on both versions.
The pytest-10 parametrize warning only appears with newer pytest, as in CI; my local pytest doesn't emit it, but
list(...)is exactly what it asks for.🤖 Generated with Claude Code