Created
September 17, 2012 15:56
-
-
Save diogobaeder/3738165 to your computer and use it in GitHub Desktop.
Alternative to discard stdout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from contextlib import contextmanager | |
from StringIO import StringIO | |
import os | |
import sys | |
from unittest import TestCase | |
class MyTest(TestCase): | |
@contextmanager | |
def discard_print(self): | |
old_out = sys.stdout | |
sys.stdout = StringIO() | |
yield | |
sys.stdout = old_out | |
def test_my_stuff(self): | |
with self.discard_print(): | |
# test my stuff here | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment