4040else :
4141 logging_StreamHandler = logging .StreamHandler
4242
43-
4443DEFAULT_LOG_FORMAT = "%(levelname)-8s %(name)s:%(filename)s:%(lineno)d %(message)s"
4544DEFAULT_LOG_DATE_FORMAT = "%H:%M:%S"
4645_ANSI_ESCAPE_SEQ = re .compile (r"\x1b\[[\d;]+m" )
@@ -335,16 +334,6 @@ def __init__(self) -> None:
335334 """Create a new log handler."""
336335 super ().__init__ (StringIO ())
337336 self .records : List [logging .LogRecord ] = []
338- self .set_when (None )
339-
340- def set_when (self , when : Optional [str ]) -> None :
341- """Prepare for the given test phase (setup/call/teardown)."""
342- self ._when = when
343-
344- def get_when (self ) -> Optional [str ]:
345- return self ._when
346-
347- when = property (get_when , set_when )
348337
349338 def emit (self , record : logging .LogRecord ) -> None :
350339 """Keep the log records in a list in addition to the log text."""
@@ -355,6 +344,10 @@ def reset(self) -> None:
355344 self .records = []
356345 self .stream = StringIO ()
357346
347+ def clear (self ) -> None :
348+ self .records .clear ()
349+ self .stream = StringIO ()
350+
358351 def handleError (self , record : logging .LogRecord ) -> None :
359352 if logging .raiseExceptions :
360353 # Fail the test if the log message is bad (emit failed).
@@ -450,8 +443,7 @@ def messages(self) -> List[str]:
450443
451444 def clear (self ) -> None :
452445 """Reset the list of log records and the captured log text."""
453- self .handler .reset ()
454- self ._item .stash [caplog_records_key ][self .handler .when ] = self .records
446+ self .handler .clear ()
455447
456448 def set_level (self , level : Union [int , str ], logger : Optional [str ] = None ) -> None :
457449 """Set the level of a logger for the duration of a test.
@@ -706,7 +698,6 @@ def _runtest_for(self, item: nodes.Item, when: str) -> Generator[None, None, Non
706698 level = self .log_level ,
707699 ) as report_handler :
708700 caplog_handler .reset ()
709- caplog_handler .set_when (when )
710701 report_handler .reset ()
711702 item .stash [caplog_records_key ][when ] = caplog_handler .records
712703 item .stash [caplog_handler_key ] = caplog_handler
0 commit comments