mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
Issue #23016: A warning no longer produces AttributeError when the program
is run with pythonw.exe.
This commit is contained in:
parent
82c05a54a2
commit
60599525c5
3 changed files with 15 additions and 0 deletions
|
@ -631,6 +631,15 @@ class _WarningsTests(BaseTest, unittest.TestCase):
|
||||||
finally:
|
finally:
|
||||||
globals_dict['__file__'] = oldfile
|
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):
|
class WarningsDisplayTests(BaseTest):
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,9 @@ def showwarning(message, category, filename, lineno, file=None, line=None):
|
||||||
"""Hook to write a warning to a file; replace if you like."""
|
"""Hook to write a warning to a file; replace if you like."""
|
||||||
if file is None:
|
if file is None:
|
||||||
file = sys.stderr
|
file = sys.stderr
|
||||||
|
if file is None:
|
||||||
|
# sys.stderr is None when ran with pythonw.exe - warnings get lost
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
file.write(formatwarning(message, category, filename, lineno, line))
|
file.write(formatwarning(message, category, filename, lineno, line))
|
||||||
except OSError:
|
except OSError:
|
||||||
|
|
|
@ -39,6 +39,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #23016: A warning no longer produces an AttributeError when the program
|
||||||
|
is run with pythonw.exe.
|
||||||
|
|
||||||
- Issue #21775: shutil.copytree(): fix crash when copying to VFAT. An exception
|
- Issue #21775: shutil.copytree(): fix crash when copying to VFAT. An exception
|
||||||
handler assumed that that OSError objects always have a 'winerror' attribute.
|
handler assumed that that OSError objects always have a 'winerror' attribute.
|
||||||
That is not the case, so the exception handler itself raised AttributeError
|
That is not the case, so the exception handler itself raised AttributeError
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue