Skip to content

Different behavior of captureWarnings between python 3.14.3 and 3.14.3t #146358

@abulgher

Description

@abulgher

Bug report

Bug description:

Consider the following code snippet as a MWE

import logging
import warnings


def emit_user_warning() -> None:
    """Trigger the warning that we expect pytest-style helpers to see."""

    warnings.warn('MWE warning', UserWarning)


def main() -> None:
    """Log the warning while capturing it via ``warnings.catch_warnings``."""

    logging.captureWarnings(True)
    warnings.simplefilter('always', UserWarning)

    with warnings.catch_warnings(record=True) as recorded:
        emit_user_warning()
        print('warnings captured inside catch_warnings:', len(recorded))
        for entry in recorded:
            print('  captured message:', entry.message)


if __name__ == '__main__':
    main()

Executing this script with python3.14 will generate the following output:

$ `uv python find 3.14` nogil_warning_capture.py 
warnings captured inside catch_warnings: 1
  captured message: MWE warning

while the output on python3.14t will be:

$ `uv python find 3.14t` nogil_warning_capture.py 
warnings captured inside catch_warnings: 0

I am actually expecting the behavior of 3.14 to be the correct one.

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.14bugs and security fixes3.15new features, bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-free-threadingtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions