Skip to content

Cover diagnostic warning retention and reset behavior with tests #94

Open

Description

@owenthcarey

Problem

The warning log in src/pythonnative/diagnostics.py retains the most recent 200 messages, returns a snapshot in oldest-first order, and clears both messages and deduplication keys when clear_warnings() is called.

tests/test_core_semantics.py already tests deduplication for an explicit key and some production-mode behavior, but it doesn't directly cover log eviction, snapshot isolation, or resetting deduplication. These guarantees keep diagnostics useful during long preview sessions and prevent tests from leaking warning state.

Requested change

Extend the existing diagnostics-primitives section of tests/test_core_semantics.py, using its dev_mode fixture and pytest capture helpers. No runtime changes are expected.

Acceptance criteria

  • Record 201 distinct warnings and assert that exactly the newest 200 remain in oldest-first order.
  • Mutating the list returned by get_warnings() doesn't change the internal log.
  • clear_warnings() empties the log and allows a previously used warn_once key to emit again.
  • Repeated warn_once() calls without a key deduplicate by message; different messages remain distinct.
  • In production mode, calling warn_once() doesn't consume its key: after enabling dev mode, the same key can still emit.
  • Tests restore diagnostic state and use no sleeps, threads, or native backends.

Verification

uv run pytest tests/test_core_semantics.py -q
./scripts/check.sh

Suggested commit message

Following CONTRIBUTING.md:

test(diagnostics): cover warning retention and reset behavior

Before starting

Please follow the issue-claiming process: check for an assignee or linked pull request, comment to claim the issue, and wait for a maintainer to assign it before opening a pull request. Contributor setup is in CONTRIBUTING.md.

Activity

  1. glenlouis8 commented on Oct 9, 2026

    @glenlouis8
    Contributor

    Hi, I'd like to take this one. I've contributed a few PRs here before (#49, #48, #68, #81). I'll add tests for how diagnostic warnings are kept and reset, and open a PR within a few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

good first issue

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions