|
27 | 27 |
|
28 | 28 |
|
29 | 29 | 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 |
58 | 31 | def __init__(self): |
59 | | - """Create a new log handler.""" |
60 | 32 | super().__init__(io.StringIO()) |
61 | 33 | self.records = [] |
62 | 34 |
|
63 | 35 | def emit(self, record) -> None: |
64 | | - """Keep the log records in a list in addition to the log text.""" |
65 | 36 | self.records.append(record) |
66 | 37 | super().emit(record) |
67 | 38 |
|
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 | | - |
76 | 39 | 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 |
83 | 41 |
|
84 | 42 |
|
85 | 43 | @contextlib.contextmanager |
|
0 commit comments