def METHOD_NAME(self, object, ui_kwargs=None):
    """Context manager to create a UI and dispose it upon exit.
    This method does not modify the states of the :class:`UITester` and is
    not a requirement for using other methods on the tester.
    Parameters
    ----------
    object : HasTraits
        An instance of HasTraits for which a GUI will be created.
    ui_kwargs : dict or None, optional
        Keyword arguments to be provided to ``HasTraits.edit_traits``.
        Default is to call ``edit_traits`` with no additional keyword
        arguments.
    Yields
    ------
    ui : traitsui.ui.UI
    """
    ui_kwargs = {} if ui_kwargs is None else ui_kwargs
    ui = object.edit_traits(**ui_kwargs)
    try:
        yield ui
    finally:
        with reraise_exceptions():
            if self._auto_process_events:
                # At the end of a test, there may be events to be
                # processed. If dispose happens first, those events will be
                # processed after various editor states are removed,
                # causing errors. But if we are asked not to process
                # events, then don't.
                process_cascade_events()
            try:
                ui.dispose()
            finally:
                # dispose is not atomic and may push more events to the
                # event queue. Flush those too unless we are asked not to.
                if self._auto_process_events:
                    process_cascade_events()