##// END OF EJS Templates
BUG: Explicitly close Tee in AssertPrints and AssertNotPrints...
Scott Sanderson -
Show More
@@ -365,6 +365,7 b' class AssertPrints(object):'
365 365 setattr(sys, self.channel, self.buffer if self.suppress else self.tee)
366 366
367 367 def __exit__(self, etype, value, traceback):
368 try:
368 369 if value is not None:
369 370 # If an error was raised, don't check anything else
370 371 return False
@@ -377,6 +378,8 b' class AssertPrints(object):'
377 378 else:
378 379 assert s in printed, notprinted_msg.format(s, self.channel, printed)
379 380 return False
381 finally:
382 self.tee.close()
380 383
381 384 printed_msg = """Found {0!r} in printed output (on {1}):
382 385 -------
@@ -389,18 +392,24 b' class AssertNotPrints(AssertPrints):'
389 392
390 393 Counterpart of AssertPrints"""
391 394 def __exit__(self, etype, value, traceback):
395 try:
392 396 if value is not None:
393 397 # If an error was raised, don't check anything else
398 self.tee.close()
394 399 return False
395 400 self.tee.flush()
396 401 setattr(sys, self.channel, self.orig_stream)
397 402 printed = self.buffer.getvalue()
398 403 for s in self.s:
399 404 if isinstance(s, _re_type):
400 assert not s.search(printed), printed_msg.format(s.pattern, self.channel, printed)
405 assert not s.search(printed),printed_msg.format(
406 s.pattern, self.channel, printed)
401 407 else:
402 assert s not in printed, printed_msg.format(s, self.channel, printed)
408 assert s not in printed, printed_msg.format(
409 s, self.channel, printed)
403 410 return False
411 finally:
412 self.tee.close()
404 413
405 414 @contextmanager
406 415 def mute_warn():
General Comments 0
You need to be logged in to leave comments. Login now