[issue42186] unittest overrides more serious warnings filter added before unittest.main()

2020-10-31 Thread STINNER Victor


Change by STINNER Victor :


--
nosy:  -vstinner

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42186] unittest overrides more serious warnings filter added before unittest.main()

2020-10-30 Thread Nick Coghlan


Nick Coghlan  added the comment:

Closing the old one as partially fixed, and linking here as a superseder makes 
sense to me, so I went ahead and did that.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42186] unittest overrides more serious warnings filter added before unittest.main()

2020-10-30 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

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?

--
nosy: +terry.reedy, vstinner
versions:  -Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42186] unittest overrides more serious warnings filter added before unittest.main()

2020-10-28 Thread Karthikeyan Singaravelan


Karthikeyan Singaravelan  added the comment:

Seems to be a duplicate of https://bugs.python.org/issue15626. See also 
https://bugs.python.org/issue31975

--
nosy: +ncoghlan

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42186] unittest overrides more serious warnings filter added before unittest.main()

2020-10-28 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
nosy: +xtreak

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42186] unittest overrides more serious warnings filter added before unittest.main()

2020-10-28 Thread Yilei Yang


New submission from Yilei Yang :

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 "", line 1, in 
  File "lib.py", line 6, in a_function
warnings.warn('Do not use.', MyWarning)
lib.MyWarning: Do not use.

--
components: Library (Lib)
messages: 379843
nosy: yilei
priority: normal
severity: normal
status: open
title: unittest overrides more serious warnings filter added before 
unittest.main()
type: behavior
versions: Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com