Skip to content

Clean up warnings in the test suite - #2917

Merged
pvcraven merged 2 commits into
developmentfrom
tests/clean-up-warnings
Oct 6, 2026
Merged

pvcraven merged 2 commits into
developmentfrom
tests/clean-up-warnings

Conversation

@pvcraven

@pvcraven pvcraven commented Oct 5, 2026

Copy link
Copy Markdown
Member

Summary

The test suite printed 240 warnings; it now prints none. Every group from the CI warnings summary is handled:

Warning Cause Fix
PytestRemovedIn10Warning: non-Collection iterable passed to parametrize test_examples.py and test_tutorials.py passed generators Wrap them in list(...)
DeprecationWarning: load_module() (230 of them) Examples and tutorials were run with SourceFileLoader(...).load_module(), which Python 3.15 removes Use runpy.run_path(path, run_name="__main__")
PerformanceWarning: draw_text is slow Tests and examples that use draw_text on purpose Mark those tests to ignore PerformanceWarning (only those tests, not the whole suite)
PytestUnraisableExceptionWarning: AttributeError: ... no attribute '_glo' A small real bug (below) Guard the __del__ methods
UserWarning: Container size is 0 test_container_size_zero tests that case on purpose; test_works_in_box_layout had a layout with no size The first now asserts the warning with pytest.warns; the second gives its layout a size, like the anchor-layout test next to it

Examples and tutorials ran twice

loader.exec_module(loader.load_module()) ran each file twice: load_module() already executes the module, and then exec_module() ran it again. A throwaway file confirmed it executed 2 times. runpy.run_path runs it once, as python -m would, 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__ read self._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. OpenGLVertexArray stores its handle as the slot glo, not _glo, so its guard checks that.

Tests

  • New test_failed_creation_collected_quietly (tests/unit/gl/test_gl_gc.py): in both auto and context_gc modes, it makes texture and framebuffer creation fail and garbage-collects. It then checks that no unraisable errors were reported, using sys.unraisablehook. On development it reports the 3 AttributeErrors.

  • Normal cleanup still works: the existing test_context_gc checks that normally created objects are still cleaned up. Using _glo for 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:

    • before: 1484 passed, 240 warnings, 44.9 s
    • after: 1485 passed, 0 warnings, 39.2 s

    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

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>
@pvcraven
pvcraven merged commit 6523645 into development Oct 6, 2026
7 checks passed
@pvcraven
pvcraven deleted the tests/clean-up-warnings branch October 6, 2026 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant