Skip to content

Commit 3d68f6e

Browse files
committed
mimimize LogCaptureHandler, and reduce pytest citation
1 parent eb01d6b commit 3d68f6e

File tree

1 file changed

+2
-44
lines changed

1 file changed

+2
-44
lines changed

Lib/test/test_support.py

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -27,59 +27,17 @@
2727

2828

2929
class LogCaptureHandler(logging.StreamHandler):
30-
"""
31-
A logging handler that stores log records and the log text.
32-
33-
Derived from pytest caplog.
34-
35-
The MIT License (MIT)
36-
37-
Copyright (c) 2004 Holger Krekel and others
38-
39-
Permission is hereby granted, free of charge, to any person obtaining a copy of
40-
this software and associated documentation files (the "Software"), to deal in
41-
the Software without restriction, including without limitation the rights to
42-
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
43-
of the Software, and to permit persons to whom the Software is furnished to do
44-
so, subject to the following conditions:
45-
46-
The above copyright notice and this permission notice shall be included in all
47-
copies or substantial portions of the Software.
48-
49-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55-
SOFTWARE.
56-
"""
57-
30+
# Inspired by pytest's caplog
5831
def __init__(self):
59-
"""Create a new log handler."""
6032
super().__init__(io.StringIO())
6133
self.records = []
6234

6335
def emit(self, record) -> None:
64-
"""Keep the log records in a list in addition to the log text."""
6536
self.records.append(record)
6637
super().emit(record)
6738

68-
def reset(self):
69-
self.records = []
70-
self.stream = io.StringIO()
71-
72-
def clear(self):
73-
self.records.clear()
74-
self.stream = io.StringIO()
75-
7639
def handleError(self, record):
77-
if logging.raiseExceptions:
78-
# Fail the test if the log message is bad (emit failed).
79-
# The default behavior of logging is to print "Logging error"
80-
# to stderr with the call stack and some extra details.
81-
# pytest wants to make such mistakes visible during testing.
82-
raise
40+
raise
8341

8442

8543
@contextlib.contextmanager

0 commit comments

Comments
 (0)