Bug report
Bug description:
If a filter is defined with action="once", the occurrence tracking is reset each time a new filter is defined. This can override the ability to effectively use action="once" if the filter manipulation occurs in a library which the user cannot control (e.g. matplotlib).
For example, the following code will only output a warning once (i.e. works as intended):
import warnings
warnings.filterwarnings("once", "test warning", UserWarning)
warnings.warn("test warning", UserWarning)
warnings.warn("test warning", UserWarning)
However, simply inserting an unrelated filter prior to the second warning will cause both to be output:
warnings.filterwarnings("once", "test warning", UserWarning)
warnings.warn("test warning", UserWarning)
warnings.filterwarnings("ignore", "something unrelated")
warnings.warn("test warning", UserWarning)
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Bug report
Bug description:
If a filter is defined with
action="once", the occurrence tracking is reset each time a new filter is defined. This can override the ability to effectively useaction="once"if the filter manipulation occurs in a library which the user cannot control (e.g.matplotlib).For example, the following code will only output a warning once (i.e. works as intended):
However, simply inserting an unrelated filter prior to the second warning will cause both to be output:
CPython versions tested on:
3.14
Operating systems tested on:
Linux