This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2020年10月28日 20:42 by yilei_not_used, last changed 2022年04月11日 14:59 by admin.
| Messages (4) | |||
|---|---|---|---|
| msg379843 - (view) | Author: Not Used (yilei_not_used) | Date: 2020年10月28日 20:42 | |
Because unittest adds a `default` filter before tests run, other warnings filters are overridden if added before.
Ideally, unittest should not make the warnings less serious, e.g. if there is already an 'error' filter that raises exception, it shouldn't "downgrade" to 'default' that simply prints.
The following example, using lib.a_function() raises exception in a regular program, but the unit test passes:
$ cat lib.py
import warnings
class MyWarning(UserWarning):
pass
warnings.filterwarnings('error', category=MyWarning)
def a_function():
warnings.warn('Do not use.', MyWarning)
$ cat lib_test.py
import unittest
import lib
class TestLib(unittest.TestCase):
def test_function(self):
lib.a_function()
if __name__ == '__main__':
unittest.main()
$ python -m unittest -v lib_test
test_function (lib_test.TestLib) ... lib.py:6: MyWarning: Do not use.
warnings.warn('Do not use.', MyWarning)
ok
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
$ python
>>> import lib
>>> lib.a_function()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "lib.py", line 6, in a_function
warnings.warn('Do not use.', MyWarning)
lib.MyWarning: Do not use.
|
|||
| msg379850 - (view) | Author: Karthikeyan Singaravelan (xtreak) * (Python committer) | Date: 2020年10月29日 00:34 | |
Seems to be a duplicate of https://bugs.python.org/issue15626. See also https://bugs.python.org/issue31975 |
|||
| msg380016 - (view) | Author: Terry J. Reedy (terry.reedy) * (Python committer) | Date: 2020年10月30日 23:59 | |
Nick and/or Victor: should this be closed in favor of #15626? or should the latter be closed as mostly fixed, with this being left open as a followup? |
|||
| msg380039 - (view) | Author: Alyssa Coghlan (ncoghlan) * (Python committer) | Date: 2020年10月31日 05:15 | |
Closing the old one as partially fixed, and linking here as a superseder makes sense to me, so I went ahead and did that. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:59:37 | admin | set | github: 86352 |
| 2020年10月31日 21:14:17 | vstinner | set | nosy:
- vstinner |
| 2020年10月31日 05:15:34 | ncoghlan | set | messages: + msg380039 |
| 2020年10月31日 05:07:43 | ncoghlan | link | issue15626 superseder |
| 2020年10月30日 23:59:51 | terry.reedy | set | nosy:
+ vstinner, terry.reedy messages: + msg380016 versions: - Python 3.6, Python 3.7 |
| 2020年10月29日 00:34:46 | xtreak | set | nosy:
+ ncoghlan messages: + msg379850 |
| 2020年10月29日 00:25:05 | xtreak | set | nosy:
+ xtreak |
| 2020年10月28日 20:42:28 | yilei_not_used | create | |