def wrap_session(config, doit):
session = Session(config)<EOL>session.exitstatus = EXIT_OK<EOL>initstate = <NUM_LIT:0><EOL>try:<EOL><INDENT>try:<EOL><INDENT>config._do_configure()<EOL>initstate = <NUM_LIT:1><EOL>config.hook.pytest_sessionstart(session=session)<EOL>initstate = <NUM_LIT:2><EOL>session.exitstatus = doit(config, session) or <NUM_LIT:0><EOL><DEDENT>except UsageError:<EOL><INDENT>raise<EOL><DEDENT>except Failed:<EOL><INDENT>session.exitstatus = EXIT_TESTSFAILED<EOL><DEDENT>except (KeyboardInterrupt, exit.Exception):<EOL><INDENT>excinfo = _pytest._code.ExceptionInfo.from_current()<EOL>exitstatus = EXIT_INTERRUPTED<EOL>if initstate <= <NUM_LIT:2> and isinstance(excinfo.value, exit.Exception):<EOL><INDENT>sys.stderr.write("<STR_LIT>".format(excinfo.typename, excinfo.value.msg))<EOL>if excinfo.value.returncode is not None:<EOL><INDENT>exitstatus = excinfo.value.returncode<EOL><DEDENT><DEDENT>config.hook.pytest_keyboard_interrupt(excinfo=excinfo)<EOL>session.exitstatus = exitstatus<EOL><DEDENT>except:  <EOL><INDENT>excinfo = _pytest._code.ExceptionInfo.from_current()<EOL>config.notify_exception(excinfo, config.option)<EOL>session.exitstatus = EXIT_INTERNALERROR<EOL>if excinfo.errisinstance(SystemExit):<EOL><INDENT>sys.stderr.write("<STR_LIT>")<EOL><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>excinfo = None  <EOL>session.startdir.chdir()<EOL>if initstate >= <NUM_LIT:2>:<EOL><INDENT>config.hook.pytest_sessionfinish(<EOL>session=session, exitstatus=session.exitstatus<EOL>)<EOL><DEDENT>config._ensure_unconfigure()<EOL><DEDENT>return session.exitstatus<EOL>
Skeleton command line program