[add] HidePrint can be configured to skip hiding for quick debugging of tests

This commit is contained in:
Darius Arnold 2018-07-20 15:04:48 +02:00
parent 7fe5d0f7a3
commit 1b815a27b8

View File

@ -14,12 +14,19 @@ class HidePrints:
"""
Used to hide all standard output the Function to be tested have, since it clutters the test results.
"""
def __init__(self, hide_prints=True):
"""Create object with hide_prints=False to disable print hiding"""
self.hide = hide_prints
def __enter__(self):
if self.hide:
self._original_stdout = sys.stdout
devnull = open(os.devnull, "w")
sys.stdout = devnull
def __exit__(self, exc_type, exc_val, exc_tb):
if self.hide:
sys.stdout = self._original_stdout