Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
aebbaeb9
Commit
aebbaeb9
authored
Apr 06, 2010
by
Philip Jenvey
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#7301: add the environment variable $PYTHONWARNINGS to supplement the -W
command line option patch from Brian Curtin
parent
c1bf677e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
0 deletions
+60
-0
Doc/using/cmdline.rst
Doc/using/cmdline.rst
+8
-0
Lib/test/test_warnings.py
Lib/test/test_warnings.py
+39
-0
Misc/NEWS
Misc/NEWS
+2
-0
Modules/main.c
Modules/main.c
+11
-0
No files found.
Doc/using/cmdline.rst
View file @
aebbaeb9
...
...
@@ -352,6 +352,8 @@ Miscellaneous options
:pep:`230` -- Warning framework
:envvar:`PYTHONWARNINGS`
.. cmdoption:: -x
...
...
@@ -547,6 +549,12 @@ These environment variables influence Python's behavior.
value instead of the value got through the C runtime. Only works on
Mac OS X.
.. envvar:: PYTHONWARNINGS
This is the equivalent to the :option:`-W` option. If set to a comma
separated string, it is equivalent to specifying :option:`-W` multiple
times.
Debug-mode variables
~~~~~~~~~~~~~~~~~~~~
...
...
Lib/test/test_warnings.py
View file @
aebbaeb9
...
...
@@ -4,6 +4,7 @@ import os
import
StringIO
import
sys
import
unittest
import
subprocess
from
test
import
test_support
import
warning_tests
...
...
@@ -674,6 +675,42 @@ class PyCatchWarningTests(CatchWarningTests):
module
=
py_warnings
class
EnvironmentVariableTests
(
BaseTest
):
def
test_single_warning
(
self
):
newenv
=
os
.
environ
.
copy
()
newenv
[
"PYTHONWARNINGS"
]
=
"ignore::DeprecationWarning"
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
"import sys; sys.stdout.write(str(sys.warnoptions))"
],
stdout
=
subprocess
.
PIPE
,
env
=
newenv
)
self
.
assertEqual
(
p
.
stdout
.
read
(),
"['ignore::DeprecationWarning']"
)
def
test_comma_separated_warnings
(
self
):
newenv
=
os
.
environ
.
copy
()
newenv
[
"PYTHONWARNINGS"
]
=
(
"ignore::DeprecationWarning,"
"ignore::UnicodeWarning"
)
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-c"
,
"import sys; sys.stdout.write(str(sys.warnoptions))"
],
stdout
=
subprocess
.
PIPE
,
env
=
newenv
)
self
.
assertEqual
(
p
.
stdout
.
read
(),
"['ignore::DeprecationWarning', 'ignore::UnicodeWarning']"
)
def
test_envvar_and_command_line
(
self
):
newenv
=
os
.
environ
.
copy
()
newenv
[
"PYTHONWARNINGS"
]
=
"ignore::DeprecationWarning"
p
=
subprocess
.
Popen
([
sys
.
executable
,
"-W"
"ignore::UnicodeWarning"
,
"-c"
,
"import sys; sys.stdout.write(str(sys.warnoptions))"
],
stdout
=
subprocess
.
PIPE
,
env
=
newenv
)
self
.
assertEqual
(
p
.
stdout
.
read
(),
"['ignore::UnicodeWarning', 'ignore::DeprecationWarning']"
)
class
CEnvironmentVariableTests
(
EnvironmentVariableTests
):
module
=
c_warnings
class
PyEnvironmentVariableTests
(
EnvironmentVariableTests
):
module
=
py_warnings
def
test_main
():
py_warnings
.
onceregistry
.
clear
()
c_warnings
.
onceregistry
.
clear
()
...
...
@@ -683,6 +720,8 @@ def test_main():
_WarningsTests
,
CWarningsDisplayTests
,
PyWarningsDisplayTests
,
CCatchWarningTests
,
PyCatchWarningTests
,
CEnvironmentVariableTests
,
PyEnvironmentVariableTests
)
...
...
Misc/NEWS
View file @
aebbaeb9
...
...
@@ -12,6 +12,8 @@ What's New in Python 2.7 beta 1?
Core and Builtins
-----------------
- Issue #7301: Add environment variable $PYTHONWARNINGS.
- Issue #8329: Don't return the same lists from select.select when no fds are
changed.
...
...
Modules/main.c
View file @
aebbaeb9
...
...
@@ -83,6 +83,7 @@ static char *usage_3 = "\
can be supplied multiple times to increase verbosity
\n
\
-V : print the Python version number and exit (also --version)
\n
\
-W arg : warning control; arg is action:message:category:module:lineno
\n
\
also PYTHONWARNINGS=arg
\n
\
-x : skip first line of source, allowing use of non-Unix forms of #!cmd
\n
\
"
;
static
char
*
usage_4
=
"\
...
...
@@ -420,6 +421,16 @@ Py_Main(int argc, char **argv)
(
p
=
Py_GETENV
(
"PYTHONNOUSERSITE"
))
&&
*
p
!=
'\0'
)
Py_NoUserSiteDirectory
=
1
;
if
((
p
=
Py_GETENV
(
"PYTHONWARNINGS"
))
&&
*
p
!=
'\0'
)
{
char
*
warning
=
strtok
(
p
,
","
);
while
(
warning
!=
NULL
)
{
PySys_AddWarnOption
(
warning
);
warning
=
strtok
(
NULL
,
","
);
}
}
if
(
command
==
NULL
&&
module
==
NULL
&&
_PyOS_optind
<
argc
&&
strcmp
(
argv
[
_PyOS_optind
],
"-"
)
!=
0
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment