Alex | 265f45e | 2019-04-23 18:51:23 -0500 | [diff] [blame] | 1 | import contextlib |
| 2 | import io |
| 3 | import sys |
| 4 | import unittest |
| 5 | |
| 6 | |
| 7 | class 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 |