Skip to content

test_warnings not restoring filters for free threading tests #155608

Description

@johng

Bug description:

PYTHONWARNINGS=default ./python.exe -W default -m test test_warnings
Using random seed: 2934466897
0:00:00 load avg: 8.99 mem: 287.4 MiB Run 1 test sequentially in a single process
0:00:00 load avg: 8.99 mem: 287.4 MiB [1/1] test_warnings
Warning -- warnings.filters was modified by test_warnings
Warning --   Before: (12918522352, [('default', None, <class 'Warning'>, None, 0)], [('default', None, <class 'Warning'>, None, 0)])
Warning --   After:  (12918522352, [('default', None, <class 'Warning'>, None, 0)], []) 
0:00:20 load avg: 7.32 mem: 392.4 MiB [1/1/1] test_warnings failed (env changed)

This appears to race because the setUp is calling resetwarnings without getting it's own context.

This does not appear on the Cpython CI since --py-debug is used I believe which starts the warnings filter by default as an empty list so less likely to race, this occurred to me when running cpython tests against a release build and this test would not work.

The root cause I think is due to regr test asserting that the env hasn't been changed, however due to starting the test with warnings that are cleared this does not hold true

CPython versions tested on:

CPython main branch

Operating systems tested on:

Macos

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions