Mark Dickinson <dicki...@gmail.com> added the comment: +1 for Benjamin's patch, having just been bitten by this exact problem.
I'm trying to do unit testing, checking both that a piece of code produces a DeprecationWarning and that it gives the correct result, with something like: with warnings.catch_warnings(): warnings.filterwarnings("ignore", category=DeprecationWarning) self.assertEqual(my_func(my_args), expected_result) with warnings.catch_warnings(): warnings.filterwarnings("error", category=DeprecationWarning) self.assertRaises(DeprecationWarning, my_func, *my_args) The first call still registers the warning, even though it's ignored, so the second assertRaises fails. Benjamin's patch would seem to provide a way to fix this. Perhaps I'm missing an obvious better way to do this. N.B. The above is a too simple version of the real problem: it actually works as intended, for fragile reasons: the "ignore"d warning is registered on __name__, while the "always"d warning ends up being registered on unittest.case, so there's no conflict. ---------- nosy: +mark.dickinson _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue4180> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com