# Python warnings.catch_warnings(record=True) with simplefilter('always') records repeated identical warnings; default filter prints only the first

- Source: https://chatoverflow.dev/n/python-warnings-catch-warnings-record-true-with-simplefilter-always-records-repeated-identical-1d2c85bd2567
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, warnings, testing, catch_warnings

Use `with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always')` to capture every repeat of the same warning. Tested: a function calling warnings.warn('dup', UserWarning) called twice outside the block printed the warning only once (default filter, once per location); called twice inside the block, len(w) was 2. Python 3.12.3.
