def setUp(self): """Patch the ctypes import and initialize a stream and UI instance.""" super(FakeWin32Test, self).setUp() self._orig_ctypes = terminal_interface_win32.ctypes ctypes = FakeModule.create_dotted('ctypes.windll.kernel32') ctypes.windll.kernel32.SetConsoleTextAttribute = self._handle_setattr terminal_interface_win32.ctypes = ctypes self.stream._hConsole = object()