➜

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
标题: Add environment variable $PYTHONWARNINGS
类型: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.2, Python 2.7
process
状态: closed Resolution: fixed
Dependencies: 后续:
分配给: pjenvey 抄送列表: barry, brian.curtin, eric.araujo, pitrou, pjenvey, skrah
优先级: normal 关键字: needs review, patch

Created on 2009-11-10 15:05 by barry, last changed 2022-04-11 14:56 by admin. This issue is now closed.

文件
文件名 上传时间 Description 编辑
issue7301.diff brian.curtin, 2010-02-06 23:33 trunk patch
issue7301-2.diff pjenvey, 2010-04-06 23:03
issue7301-py3k.diff pjenvey, 2010-04-08 01:12
Messages (15)
msg95117 - (view) Author: Barry A. Warsaw (barry) * (Python committer) 日期: 2009-11-10 15:05
It would be very useful to have an environment variable $PYTHONWARNINGS,
tied to the -W option for silencing various warnings (most importantly,
DeprecationWarnings).

Use case: a test suite running many subprocesses, testing that those
subproc output is clean.  DeprecationWarnings cannot easily be
suppressed by passing -W flags all around or using liberally sprinkled
filterwarnings().  Setting $PYTHONWARNINGS once and for all to silence
all processes would be very useful.
msg95200 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) 日期: 2009-11-13 21:15
I attached a patch against trunk r76237 which seems to cover this, sans
official tests. I looked around and didn't find a good place for
specifically testing environment variables. I could add test code in
test_warnings if that's the best place.

The patch allows multiple warnings to be passed to the environment
variable as a comma separated string, and works in conjunction with -W.

Let me know what you think.
msg95202 - (view) Author: Philip Jenvey (pjenvey) * (Python committer) 日期: 2009-11-13 21:28
test_warnings is probably the best place since test_cmd_line ignores 
environment variables
msg95210 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) 日期: 2009-11-13 22:10
Added a patch which includes tests in test_warnings. There are tests for
a single warning, two comma separated warnings, and one env var warning
and one command line warning at the same time.
msg97797 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) 日期: 2010-01-15 00:40
fixed a tab/space issue
msg98972 - (view) Author: Brian Curtin (brian.curtin) * (Python committer) 日期: 2010-02-06 23:33
Updated patch, tests weren't working.
msg102504 - (view) Author: Philip Jenvey (pjenvey) * (Python committer) 日期: 2010-04-06 23:03
Looks good to me. Updated patch with a couple whitespace changes
msg102505 - (view) Author: Barry A. Warsaw (barry) * (Python committer) 日期: 2010-04-06 23:14
Patch looks good to me too.  Do any of you have commit privileges?  If so, please commit this.  If not assign the issue to me and I'll do it.
msg102515 - (view) Author: Philip Jenvey (pjenvey) * (Python committer) 日期: 2010-04-07 04:06
applied in r79878 - r79881, thanks!
msg102520 - (view) Author: Philip Jenvey (pjenvey) * (Python committer) 日期: 2010-04-07 06:31
I committed a somewhat different version of this patch to py3k to handle the warn options now calling for wchars, but this needs more work. Some of the buildbots are unhappy

Seems like the py3k version either needs to fully decode the env values to a unicode obj via the file system encoding (which I doubt is initialized at this point)/surrogateescape, or use something along the lines of char2wchar in python.c
msg102582 - (view) Author: Philip Jenvey (pjenvey) * (Python committer) 日期: 2010-04-08 01:12
Here's a patch for py3k using the same char2wchar as the argv decoder for posix, and better windows handling. Plus an additional nonascii value test. Patch is against r79980 for clarity
msg102761 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) 日期: 2010-04-10 02:24
The tests don't look good to me. You should use p.communicate() rather than p.stdout.read(). Also, check the error return code and raise an error if it's non-zero.
msg102887 - (view) Author: Stefan Krah (skrah) * (Python committer) 日期: 2010-04-11 21:00
The changes in main.c in r79881 don't look right:

strtok() is used on the string returned by getenv(), which must not
be modified.

Also (and this admittedly cosmetic), perhaps use a static buffer like
wchar_t warning[128] or use a single allocation before the for loop.
What is the maximum length for a single warning?
msg102888 - (view) Author: Philip Jenvey (pjenvey) * (Python committer) 日期: 2010-04-11 21:10
The pending patch for py3k fixes the modification of the env value (trunk already has a fix for that).

That patch is also doing the conversion to wchar_t via the char2wchar function now, with that reusing a single buffer seems out of the question
msg103146 - (view) Author: Philip Jenvey (pjenvey) * (Python committer) 日期: 2010-04-14 21:04
py3k should be taken care of as of r80066+r80075
历史
日期 用户 动作 参数
2022-04-11 14:56:54admin修改github: 51550
2010-04-14 21:04:43pjenvey修改状态: open -> closed
resolution: accepted -> fixed
消息: + msg103146
2010-04-11 21:10:48pjenvey修改消息: + msg102888
2010-04-11 21:00:24skrah修改抄送: + skrah
消息: + msg102887
2010-04-10 02:24:59pitrou修改抄送: + pitrou
消息: + msg102761
2010-04-08 01:12:10pjenvey修改文件: + issue7301-py3k.diff

消息: + msg102582
2010-04-07 06:31:02pjenvey修改状态: closed -> open
assignee: pjenvey
resolution: fixed -> accepted
消息: + msg102520
2010-04-07 04:06:24pjenvey修改状态: open -> closed
resolution: accepted -> fixed
消息: + msg102515
2010-04-06 23:14:50barry修改resolution: accepted
消息: + msg102505
2010-04-06 23:03:17pjenvey修改文件: + issue7301-2.diff

消息: + msg102504
2010-02-06 23:33:39brian.curtin修改文件: + issue7301.diff

消息: + msg98972
2010-02-06 23:32:38brian.curtin修改文件: - issue7301.diff
2010-02-06 22:50:08eric.araujo修改抄送: + eric.araujo
2010-01-15 00:40:51brian.curtin修改文件: + issue7301.diff

消息: + msg97797
2010-01-15 00:39:42brian.curtin修改文件: - issue7301.patch
2010-01-15 00:39:38brian.curtin修改文件: - issue7301_v2.patch
2010-01-13 02:08:33brian.curtin修改优先级: normal
keywords: + needs review
stage: patch review
2009-11-13 22:10:20brian.curtin修改文件: + issue7301_v2.patch

消息: + msg95210
2009-11-13 21:28:40pjenvey修改消息: + msg95202
2009-11-13 21:15:46brian.curtin修改文件: + issue7301.patch

抄送: + brian.curtin
消息: + msg95200

keywords: + patch
2009-11-10 23:58:46pjenvey修改抄送: + pjenvey
2009-11-10 15:05:29barry创建