diff -r c426da77695f Lib/test/test_warnings.py --- a/Lib/test/test_warnings.py Mon Dec 08 18:01:15 2014 -0500 +++ b/Lib/test/test_warnings.py Tue Dec 09 13:43:27 2014 +0200 @@ -666,6 +666,15 @@ class _WarningsTests(BaseTest, unittest. finally: globals_dict['__file__'] = oldfile + def test_stderr_none(self): + rc, stdout, stderr = assert_python_ok("-c", + "import sys; sys.stderr = None; " + "import warnings; warnings.simplefilter('always'); " + "warnings.warn('Warning!')") + self.assertEqual(stdout, b'') + self.assertNotIn(b'Warning!', stderr) + self.assertNotIn(b'Error', stderr) + class WarningsDisplayTests(BaseTest): diff -r c426da77695f Lib/warnings.py --- a/Lib/warnings.py Mon Dec 08 18:01:15 2014 -0500 +++ b/Lib/warnings.py Tue Dec 09 13:43:27 2014 +0200 @@ -11,6 +11,9 @@ def showwarning(message, category, filen """Hook to write a warning to a file; replace if you like.""" if file is None: file = sys.stderr + if file is None: + # sys.stderr is None when ran with pythonw.exe - warnings get lost + return try: file.write(formatwarning(message, category, filename, lineno, line)) except OSError: