| 334 | setattr(sys, self.channel, self.buffer if self.suppress else self.tee) |
| 335 | |
| 336 | def __exit__(self, etype: Optional[Type[BaseException]], value: Optional[BaseException], traceback: Optional[TracebackType]): |
| 337 | __tracebackhide__ = True |
| 338 | |
| 339 | try: |
| 340 | if value is not None: |
| 341 | # If an error was raised, don't check anything else |
| 342 | return False |
| 343 | self.tee.flush() |
| 344 | setattr(sys, self.channel, self.orig_stream) |
| 345 | printed = self.buffer.getvalue() |
| 346 | for s in self.s: |
| 347 | if isinstance(s, _re_type): |
| 348 | assert s.search(printed), notprinted_msg.format(s.pattern, self.channel, printed) |
| 349 | else: |
| 350 | assert s in printed, notprinted_msg.format(s, self.channel, printed) |
| 351 | return False |
| 352 | finally: |
| 353 | self.tee.close() |
| 354 | |
| 355 | printed_msg = """Found {0!r} in printed output (on {1}): |
| 356 | ------- |