Merged revisions 79878-79880 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r79878 | philip.jenvey | 2010-04-06 16:24:45 -0700 (Tue, 06 Apr 2010) | 4 lines

  #7301: add the environment variable $PYTHONWARNINGS to supplement the -W
  command line option
  patch from Brian Curtin
........
  r79879 | benjamin.peterson | 2010-04-06 16:32:27 -0700 (Tue, 06 Apr 2010) | 1 line

  tell people to update python.man, too
........
  r79880 | philip.jenvey | 2010-04-06 16:38:57 -0700 (Tue, 06 Apr 2010) | 1 line

  document new PYTHONWARNINGS env var
........
diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py
index 7bd7191..fa83fca 100644
--- a/Lib/test/test_warnings.py
+++ b/Lib/test/test_warnings.py
@@ -4,6 +4,7 @@
 from io import StringIO
 import sys
 import unittest
+import subprocess
 from test import support
 
 from test import warning_tests
@@ -685,6 +686,42 @@
     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(), b"['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(),
+                b"['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(),
+                b"['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()
@@ -696,6 +733,8 @@
                                 _WarningsTests,
                                 CWarningsDisplayTests, PyWarningsDisplayTests,
                                 CCatchWarningTests, PyCatchWarningTests,
+                                CEnvironmentVariableTests,
+                                PyEnvironmentVariableTests
                              )