[issue28835] Change in behavior when overriding warnings.showwarning and with catch_warnings(record=True)

Martin Panter report at bugs.python.org
Mon Dec 5 21:53:42 EST 2016


Martin Panter added the comment:

Actually, I found a regression. Looks like you also need to cancel any showwarning() function set by the user:

>>> import warnings
>>> warnings.showwarning = print
>>> with warnings.catch_warnings(record=True) as recording:
...     warnings.warn("hi")  # Unpatched did not call print()
... 
hi <class 'UserWarning'> __main__ 2 None None
>>> recording  # Unpatched returned the warning here
[]

Also, should the documentation of catch_warnings() be amended to say that there is no longer a custom showwarning() function? The recording mechanism is now an internal detail, and not accessible by calling showwarning().

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue28835>
_______________________________________


More information about the Python-bugs-list mailing list