Context manager for checking that certain output *isn't* produced. Counterpart of AssertPrints
| 385 | """ |
| 386 | |
| 387 | class AssertNotPrints(AssertPrints): |
| 388 | """Context manager for checking that certain output *isn't* produced. |
| 389 | |
| 390 | Counterpart of AssertPrints""" |
| 391 | def __exit__(self, etype, value, traceback): |
| 392 | try: |
| 393 | if value is not None: |
| 394 | # If an error was raised, don't check anything else |
| 395 | self.tee.close() |
| 396 | return False |
| 397 | self.tee.flush() |
| 398 | setattr(sys, self.channel, self.orig_stream) |
| 399 | printed = self.buffer.getvalue() |
| 400 | for s in self.s: |
| 401 | if isinstance(s, _re_type): |
| 402 | assert not s.search(printed),printed_msg.format( |
| 403 | s.pattern, self.channel, printed) |
| 404 | else: |
| 405 | assert s not in printed, printed_msg.format( |
| 406 | s, self.channel, printed) |
| 407 | return False |
| 408 | finally: |
| 409 | self.tee.close() |
| 410 | |
| 411 | @contextmanager |
| 412 | def mute_warn(): |
no outgoing calls