Edit: Please notice I\'m using Python 2.6 (as tagged)
Say I have the following:
class Foo:
def bar(self):
print \'bar\'
You can suppress the output by disabling the sys.stdout and enabling it after your test is done:
import sys
import io
import unittest
class ut_Foo(unittest.TestCase):
def test_bar(self):
#You suppress here:
suppress_text = io.StringIO()
sys.stdout = suppress_text
obj = Foo()
res = obj.bar()
self.assertEqual(res, 7)
#You release here:
sys.stdout = sys.__stdout__
Got all of this from:
https://codingdose.info/2018/03/22/supress-print-output-in-python/