blob: c4a627ff7a1a9989b634d1a1a8f6880de66eab5a [file] [log] [blame]
Alex265f45e2019-04-23 18:51:23 -05001import contextlib
2import io
3import sys
4import unittest
5
6
7class CfgCheckerTestBase(unittest.TestCase):
8 dummy_base_var = 0
9
10 def _safe_import_module(self, _str):
11 _import_msg = ""
12 _module = None
13
14 try:
15 _module = __import__(_str)
16 except ImportError as e:
17 _import_msg = e.message
18
19 return _import_msg, _module
20
21 @contextlib.contextmanager
22 def redirect_output(self):
23 save_stdout = sys.stdout
24 save_stderr = sys.stderr
25 sys.stdout = io.BytesIO()
26 sys.stderr = io.BytesIO()
27 yield
28 sys.stdout = save_stdout
29 sys.stderr = save_stderr