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.

classification
Title: [EASY] test_warnings: test_exec_filename() fails when run with -Werror
Type: Stage: resolved
Components: Tests Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: brett.cannon, takluyver, vstinner
Priority: normal Keywords: easy, patch

Created on 2018-06-20 09:59 by vstinner, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 7839 merged chrisfrederickson, 2018-06-21 03:26
Messages (5)
msg320044 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-06-20 09:59
vstinner@apu$ ./python -W error -m test -v test_warnings

======================================================================
ERROR: test_exec_filename (test.test_warnings.CWarnTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vstinner/prog/python/master/Lib/test/test_warnings/__init__.py", line 450, in test_exec_filename
    exec(codeobj)
  File "<warnings-test>", line 2, in <module>
UserWarning: hello

======================================================================
ERROR: test_exec_filename (test.test_warnings.PyWarnTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/vstinner/prog/python/master/Lib/test/test_warnings/__init__.py", line 450, in test_exec_filename
    exec(codeobj)
  File "<warnings-test>", line 2, in <module>
  File "/home/vstinner/prog/python/master/Lib/warnings.py", line 318, in warn
    globals, source)
  File "/home/vstinner/prog/python/master/Lib/warnings.py", line 363, in warn_explicit
    raise message
UserWarning: hello


It seems to be a regression introduced by bpo-33375: commit 11a896652ee98aa44e59ed25237f9efb56635dcf.
msg320046 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-06-20 10:01
I consider that this issue is easy, core developers/long time contriubtors: please don't fix it, but explain how to fix it and let a newcomer to fix it!
https://mail.python.org/pipermail/python-committers/2017-June/004564.html
msg320050 - (view) Author: Thomas Kluyver (takluyver) * Date: 2018-06-20 10:12
Yes, this should be easy. I misunderstood how to use the catch_warnings context manager. I thought that catch_warnings itself set up the warnings filters you need. You actually need to do that with a separate call inside the with block, as shown here:

https://docs.python.org/3/library/warnings.html#testing-warnings
msg320194 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-06-21 16:13
New changeset 419e88d18ccc83e182afca124d42f46794022aab by Victor Stinner (Christopher Frederickson) in branch 'master':
bpo-33912: Fix test_warnings when run with -Werror (GH-7839)
https://github.com/python/cpython/commit/419e88d18ccc83e182afca124d42f46794022aab
msg320195 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2018-06-21 16:14
Thank you Christopher Frederickson for your contribution! I merged your PR. I confirm that it fixes the issue.

Thanks Thomas Kluyver for the hints ;-)
History
Date User Action Args
2022-04-11 14:59:01adminsetgithub: 78093
2018-06-21 16:14:30vstinnersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2018-06-21 16:14:17vstinnersetmessages: + msg320195
2018-06-21 16:13:03vstinnersetmessages: + msg320194
2018-06-21 03:26:44chrisfredericksonsetkeywords: + patch
stage: patch review
pull_requests: + pull_request7448
2018-06-20 18:06:27brett.cannonsetnosy: + brett.cannon
2018-06-20 10:12:27takluyversetmessages: + msg320050
2018-06-20 10:08:28serhiy.storchakasetnosy: + takluyver
2018-06-20 10:01:06vstinnersetmessages: + msg320046
2018-06-20 09:59:24vstinnercreate