[issue3781] warnings.catch_warnings fails gracelessly when recording warnings but no warnings are emitted

Nick Coghlan report at bugs.python.org
Tue Sep 9 12:38:10 CEST 2008


Nick Coghlan <ncoghlan at gmail.com> added the comment:

Reopening this because I disagree with the fix - I would prefer to see
catch_warnings() reverted back to the API and implementation* it used
prior to the test_support->warnings migration.

That version had perfectly clear semantics when no warning was issued:
w.message (and all of the other warning attributes) were None. If the
implementation of WarningsRecorder hadn't been changed then this bug
would have never arisen.

The attributes of the last warning are cached on the recorder because by
*far* the most common intended use case that makes use of the warnings
recorder is to test operations that are expected to raise a single
warning. The list of warnings is retained solely for special cases where
one operation raises multiple warnings (e.g. see the py3k warnings tests
for __hash__ inheritance).

*aside from the use of @contextmanager, obviously

----------
nosy: +ncoghlan
resolution: accepted -> 
status: closed -> open

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


More information about the Python-bugs-list mailing list