When running unittests I would like to see deprecation warnings. It appears that since Python 2.7 deprecation warnings are silenced. I'll quote from the page:
For Python 2.7, a policy decision was made to silence warnings only of interest to developers by default. DeprecationWarning and its descendants are now ignored unless otherwise requested, preventing users from seeing warnings triggered by an application. This change was also made in the branch that became Python 3.2. (Discussed on stdlib-sig and carried out in issue 7319.)
Later it appears as though I should see deprecation warnings while running unittests:
The unittest module also automatically reenables deprecation warnings when running tests.
Well.. simply put, it doesn't work for me, so I must be doing something wrong. I've tested with the following code:
import warnings
import unittest
def spam():
warnings.warn('test', DeprecationWarning, stacklevel=2)
return 'spam'
class Eggs(object):
def __init__(self):
self.spam = spam()
class Test(unittest.TestCase):
def test_warn(self):
eggs = Eggs()
self.assertEqual('spam', eggs.spam)
Then I run the code (saved in spam.py
):
python -m 'unittest' spam
And this gives me the following output:
.
----------------------------------------------------------------------
Ran 1 test in 0.001s
OK
No deprecation warning. So the question is; what am I doing wrong here?