Store the method calls that it's been called with. This is nicer than `ReturnLogger` for unit tests because the bound logger doesn't have to cooperate. **Any** method name is supported. .. versionadded:: 20.2.0
| 168 | |
| 169 | |
| 170 | class CapturingLogger: |
| 171 | """ |
| 172 | Store the method calls that it's been called with. |
| 173 | |
| 174 | This is nicer than `ReturnLogger` for unit tests because the bound logger |
| 175 | doesn't have to cooperate. |
| 176 | |
| 177 | **Any** method name is supported. |
| 178 | |
| 179 | .. versionadded:: 20.2.0 |
| 180 | """ |
| 181 | |
| 182 | calls: list[CapturedCall] |
| 183 | |
| 184 | def __init__(self) -> None: |
| 185 | self.calls = [] |
| 186 | |
| 187 | def __repr__(self) -> str: |
| 188 | return f"<CapturingLogger with {len(self.calls)} call(s)>" |
| 189 | |
| 190 | def __getattr__(self, name: str) -> Any: |
| 191 | """ |
| 192 | Capture call to `calls` |
| 193 | """ |
| 194 | |
| 195 | def log(*args: Any, **kw: Any) -> None: |
| 196 | self.calls.append(CapturedCall(name, args, kw)) |
| 197 | |
| 198 | return log |
| 199 | |
| 200 | |
| 201 | class CapturingLoggerFactory: |
no outgoing calls
searching dependent graphs…