Status: Accepted
Owner: asmeurer
Labels: Type-Defect Priority-Medium Testing
New issue 2492 by asmeurer: Better way to test warnings
http://code.google.com/p/sympy/issues/detail?id=2492
I've been using the following idiom to test code that should emit a warning:
import warnings
warnings.filterwarnings("error", "message")
<use raises(DeprecationWarning, "code") to test the warning>
warnings.filterwarnings("ignore", "message")
<test the output of code that emits to warning>
warnings.filterwarnings("default", "message")
But unfortunately, after running this once, it doesn't work again. To
quote http://docs.python.org/library/warnings.html?highlight=warnings, "One
thing to be aware of is that if a warning has already been raised because
of a once/default rule, then no matter what filters are set the warning
will not be seen again unless the warnings registry related to the warning
has been cleared."
So for example if you run sympy.test() twice in the same session, it will
fail. I can't figure out how to reset the warnings.
warnings.resetwarnings() does not do it.
This is currently being used in test_symbols.py and test_geometry.py. I
have XFAILed the tests in the 0.7.0 branch.
--
You received this message because you are subscribed to the Google Groups
"sympy-issues" group.
To post to this group, send email to sympy-issues@googlegroups.com.
To unsubscribe from this group, send email to
sympy-issues+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sympy-issues?hl=en.