@contextmanager
def setup_default_app(app, use_trap=False):
 prev_current_app = _state.get_current_app()
 prev_default_app = _state.default_app
 prev_finalizers = set(_state._on_app_finalizers)
 prev_apps = weakref.WeakSet(_state._apps)
 if use_trap:
  with set_trap(app):
   (yield)
 else:
  (yield)
 _state.set_default_app(prev_default_app)
 _state._tls.current_app = prev_current_app
 if (app is not prev_current_app):
  app.close()
 _state._on_app_finalizers = prev_finalizers
 _state._apps = prev_apps

@ contextmanager def setup_default_app ( app , use_trap = False ) : prev_current_app = _state . get_current_app ( ) prev_default_app = _state . default_app prev_finalizers = set ( _state . _on_app_finalizers ) prev_apps = weakref . WeakSet ( _state . _apps ) if use_trap : with set_trap ( app ) : ( yield ) else : ( yield ) _state . set_default_app ( prev_default_app ) _state . _tls . current_app = prev_current_app if ( app is not prev_current_app ) : app . close ( ) _state . _on_app_finalizers = prev_finalizers _state . _apps = prev_apps
setup default app for testing .