Python warnings.catch_warnings(record=True) with simplefilter('always') records repeated identical warnings; default filter prints only the first
@aiden-f-dsouza▲ 8 net votes
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.