aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/test/test_logging.py
diff options
context:
space:
mode:
authorandrei kulakov <andrei.avk@gmail.com>2021-07-25 16:17:47 -0400
committerGitHub <noreply@github.com>2021-07-25 13:17:47 -0700
commit96cf5a63d2dbadaebf236362b4c7c09c51fda55c (patch)
treeda05ccb42a61b60454a842cc1a1dcb8e322327d2 /Lib/test/test_logging.py
parent9751f85914e0ef3324671a91da34a635d48b17fb (diff)
downloadcpython-96cf5a63d2dbadaebf236362b4c7c09c51fda55c.tar.gz
cpython-96cf5a63d2dbadaebf236362b4c7c09c51fda55c.zip
bpo-42378: fixed log truncation on logging shutdown (GH-27310)
Automerge-Triggered-By: GH:vsajip
Diffstat (limited to 'Lib/test/test_logging.py')
-rw-r--r--Lib/test/test_logging.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py
index 48ed2eb2fc6..94c3fd9f28b 100644
--- a/Lib/test/test_logging.py
+++ b/Lib/test/test_logging.py
@@ -5174,6 +5174,9 @@ class BaseFileTest(BaseTest):
msg="Log file %r does not exist" % filename)
self.rmfiles.append(filename)
+ def next_rec(self):
+ return logging.LogRecord('n', logging.DEBUG, 'p', 1,
+ self.next_message(), None, None, None)
class FileHandlerTest(BaseFileTest):
def test_delay(self):
@@ -5186,11 +5189,18 @@ class FileHandlerTest(BaseFileTest):
self.assertTrue(os.path.exists(self.fn))
fh.close()
-class RotatingFileHandlerTest(BaseFileTest):
- def next_rec(self):
- return logging.LogRecord('n', logging.DEBUG, 'p', 1,
- self.next_message(), None, None, None)
+ def test_emit_after_closing_in_write_mode(self):
+ # Issue #42378
+ os.unlink(self.fn)
+ fh = logging.FileHandler(self.fn, encoding='utf-8', mode='w')
+ fh.setFormatter(logging.Formatter('%(message)s'))
+ fh.emit(self.next_rec()) # '1'
+ fh.close()
+ fh.emit(self.next_rec()) # '2'
+ with open(self.fn) as fp:
+ self.assertEqual(fp.read().strip(), '1')
+class RotatingFileHandlerTest(BaseFileTest):
def test_should_not_rollover(self):
# If maxbytes is zero rollover never occurs
rh = logging.handlers.RotatingFileHandler(