Skip to content

Adopt pytest filterwarnings = ['error']; track Pillow get_flattened_data migration #9

@rfrenchseti

Description

@rfrenchseti

Summary

[tool.pytest.ini_options] has been updated to set filterwarnings = ["error"] so any unexpected DeprecationWarning / UserWarning / ResourceWarning from astropy / numpy / Pillow / picmaker itself becomes a test failure instead of silent noise (see also priority 3 of CODEBASE_CRITIQUE.md).

Two follow-up tasks are tracked here so the temporary mitigations don't outlive their purpose.

Active mitigations

  1. Pillow 12 deprecation of Image.Image.getdata() is currently ignored via a targeted entry:

    filterwarnings = [
      "error",
      "ignore:Image.Image.getdata is deprecated:DeprecationWarning",
    ]

    src/picmaker/pil_utils.py calls image.getdata() in four places (_one_pil_to_array line 106 / 118, write_pil lines 140 / 149). Pillow 12 deprecates this in favor of image.get_flattened_data(), with removal in Pillow 14 (2027-10-15). The migration is mechanical but touches the snapshot-test fixtures because the underlying buffer dtype/shape differ.

    Action: migrate pil_utils.py to get_flattened_data(), regenerate tests/fixtures/expected/ snapshots via python tests/fixture_recipes/generate_snapshots.py, and remove the targeted ignore::DeprecationWarning filter.

  2. ReadTiff16 file-handle leak has been addressed (the body of ReadTiff16 is now wrapped in a with open(...) as f: block, so the file is closed even if my_assert(...) / raise OSError(...) short-circuits mid-parse). This fix was forced by filterwarnings = ["error"] turning the underlying ResourceWarning into pytest.PytestUnraisableExceptionWarning. WriteTiff16 has the same f = open(...) / f.close() pattern but isn't currently surfacing because no test exercises a partial write — worth converting in the same tiff16.py modernization PR (priority 6 of CODEBASE_CRITIQUE.md).

Why this matters

  • Without filterwarnings = ["error"], a new Pillow / astropy / numpy deprecation would land in the test output and nobody would notice until the runtime broke. The strict setting catches drift the day it arrives.
  • The Pillow getdata migration is a hard deadline (Pillow 14, 2027-10-15) — leaving it until just before removal risks colliding with other in-flight work.

Acceptance criteria

  • src/picmaker/pil_utils.py no longer calls Image.getdata() (use get_flattened_data()).
  • tests/fixtures/expected/ regenerated and committed.
  • ignore:Image.Image.getdata is deprecated:DeprecationWarning entry removed from [tool.pytest.ini_options].filterwarnings.
  • WriteTiff16 wrapped in with open(...) as f: so the same file-handle leak doesn't fire on partial-write failures.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions