diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-01-07 14:15:25 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-07 22:15:25 +0000 |
commit | e35430bec528dfb1a653cd457ea58b5a08543632 (patch) | |
tree | 343ad4187d0ce12139e6e7422f16c5aed75d63f7 /Lib/test/test_logging.py | |
parent | ed2656a7d313dd9fa3a963d8b4dca4438cf73bc9 (diff) | |
download | cpython-git-e35430bec528dfb1a653cd457ea58b5a08543632.tar.gz |
[3.10] bpo-42378: fixed log truncation on logging shutdown (GH-27310) (GH-30468)
Co-authored-by: andrei kulakov <andrei.avk@gmail.com>
Diffstat (limited to 'Lib/test/test_logging.py')
-rw-r--r-- | Lib/test/test_logging.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/Lib/test/test_logging.py b/Lib/test/test_logging.py index 40411b4488..03d0319306 100644 --- a/Lib/test/test_logging.py +++ b/Lib/test/test_logging.py @@ -5168,6 +5168,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): @@ -5180,11 +5183,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( |