classification
Title: imports in test_warnings changes warnings.filters
Type: Stage:
Components: Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: duplicate
Dependencies: Superseder: test_warnings modifies warnings.filters when running with "-W default"
View: 18383
Assigned To: Nosy List: martin.panter, vstinner
Priority: normal Keywords: patch

Created on 2016-04-13 00:51 by vstinner, last changed 2016-05-22 04:42 by martin.panter. This issue is now closed.

Files
File name Uploaded Description Edit
test_warnings.patch vstinner, 2016-04-13 00:51 review
Messages (3)
msg263291 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2016-04-13 00:51
---
$ ./python -Wd -m test -j0 test_warnings
Run tests in parallel using 6 child processes
0:00:01 [1/1] test_warnings
(...)
Warning -- warnings.filters was modified by test_warnings
1 test altered the execution environment:
    test_warnings
Total duration: 0:00:02
---

The problem are these two lines in test_warnings/__init__.py:
---
py_warnings = support.import_fresh_module('warnings', blocked=['_warnings'])
c_warnings = support.import_fresh_module('warnings', fresh=['_warnings'])
---

Each fresh "import warnings" calls _processoptions(sys.warnoptions) which can change warning filters.

Attached patch saves/restores warnings.filter to fix the resource warning from the test suite.

Note: the warning is not emited if tests are run sequentially (without the -jN option).
msg263294 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-04-13 01:51
Hmm your patch is a variation of the first patch in Issue 18383, and Serhiy’s comment about not fixing the underlying problem would apply: <https://bugs.python.org/issue18383#msg232451>.

I can’t remember all the details now, but it sounds like Alex’s later patch may be a slightly more desirable hack :)
msg266048 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-05-22 04:42
I suggest to use the patch from Issue 18383.
History
Date User Action Args
2016-05-22 04:42:01martin.pantersetstatus: open -> closed
superseder: test_warnings modifies warnings.filters when running with "-W default"
resolution: duplicate
messages: + msg266048
2016-04-13 01:51:37martin.pantersetnosy: + martin.panter
messages: + msg263294
2016-04-13 00:51:35vstinnercreate