<s> """<STR_LIT>""" <EOL> import py <EOL> from py . __ . test . outcome import Skipped <EOL> def pytest_addoption ( parser ) : <EOL> group = parser . getgroup ( "<STR_LIT>" ) <EOL> group . addoption ( '<STR_LIT>' , <EOL> action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> def pytest_configure ( config ) : <EOL> config . _setupstate = SetupState ( ) <EOL> def pytest_sessionfinish ( session , exitstatus ) : <EOL> if hasattr ( session . config , '<STR_LIT>' ) : <EOL> hook = session . config . hook <EOL> rep = hook . pytest__teardown_final ( session = session ) <EOL> if rep : <EOL> hook . pytest__teardown_final_logerror ( report = rep ) <EOL> def pytest_make_collect_report ( collector ) : <EOL> result = excinfo = None <EOL> try : <EOL> result = collector . _memocollect ( ) <EOL> except KeyboardInterrupt : <EOL> raise <EOL> except : <EOL> excinfo = py . code . ExceptionInfo ( ) <EOL> return CollectReport ( collector , result , excinfo ) <EOL> def pytest_runtest_protocol ( item ) : <EOL> if item . config . getvalue ( "<STR_LIT>" ) : <EOL> reports = forked_run_report ( item ) <EOL> for rep in reports : <EOL> item . config . hook . pytest_runtest_logreport ( report = rep ) <EOL> else : <EOL> runtestprotocol ( item ) <EOL> return True <EOL> def runtestprotocol ( item , log = True ) : <EOL> rep = call_and_report ( item , "<STR_LIT>" , log ) <EOL> reports = [ rep ] <EOL> if rep . passed : <EOL> reports . append ( call_and_report ( item , "<STR_LIT>" , log ) ) <EOL> reports . append ( call_and_report ( item , "<STR_LIT>" , log ) ) <EOL> return reports <EOL> def pytest_runtest_setup ( item ) : <EOL> item . config . _setupstate . prepare ( item ) <EOL> def pytest_runtest_call ( item ) : <EOL> if not item . _deprecated_testexecution ( ) : <EOL> item . runtest ( ) <EOL> def pytest_runtest_makereport ( item , call ) : <EOL> return ItemTestReport ( item , call . excinfo , call . when ) <EOL> def pytest_runtest_teardown ( item ) : <EOL> item . config . _setupstate . teardown_exact ( item ) <EOL> def pytest__teardown_final ( session ) : <EOL> call = CallInfo ( session . config . _setupstate . teardown_all , when = "<STR_LIT>" ) <EOL> if call . excinfo : <EOL> rep = TeardownErrorReport ( call . excinfo ) <EOL> return rep <EOL> def pytest_report_teststatus ( report ) : <EOL> if report . when in ( "<STR_LIT>" , "<STR_LIT>" ) : <EOL> if report . failed : <EOL> return "<STR_LIT:error>" , "<STR_LIT:E>" , "<STR_LIT>" <EOL> elif report . skipped : <EOL> return "<STR_LIT>" , "<STR_LIT:s>" , "<STR_LIT>" <EOL> else : <EOL> return "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" <EOL> def call_and_report ( item , when , log = True ) : <EOL> call = call_runtest_hook ( item , when ) <EOL> hook = item . config . hook <EOL> report = hook . pytest_runtest_makereport ( item = item , call = call ) <EOL> if log and ( when == "<STR_LIT>" or not report . passed ) : <EOL> hook . pytest_runtest_logreport ( report = report ) <EOL> return report <EOL> def call_runtest_hook ( item , when ) : <EOL> hookname = "<STR_LIT>" + when <EOL> hook = getattr ( item . config . hook , hookname ) <EOL> return CallInfo ( lambda : hook ( item = item ) , when = when ) <EOL> class CallInfo : <EOL> excinfo = None <EOL> def __init__ ( self , func , when ) : <EOL> self . when = when <EOL> try : <EOL> self . result = func ( ) <EOL> except KeyboardInterrupt : <EOL> raise <EOL> except : <EOL> self . excinfo = py . code . ExceptionInfo ( ) <EOL> def __repr__ ( self ) : <EOL> if self . excinfo : <EOL> status = "<STR_LIT>" % str ( self . excinfo . value ) <EOL> else : <EOL> status = "<STR_LIT>" % ( self . result , ) <EOL> return "<STR_LIT>" % ( self . when , status ) <EOL> def forked_run_report ( item ) : <EOL> EXITSTATUS_TESTEXIT = <NUM_LIT:4> <EOL> from py . __ . test . dist . mypickle import ImmutablePickler <EOL> ipickle = ImmutablePickler ( uneven = <NUM_LIT:0> ) <EOL> ipickle . selfmemoize ( item . config ) <EOL> ipickle . selfmemoize ( item ) <EOL> def runforked ( ) : <EOL> try : <EOL> reports = runtestprotocol ( item , log = False ) <EOL> except KeyboardInterrupt : <EOL> py . std . os . _exit ( EXITSTATUS_TESTEXIT ) <EOL> return ipickle . dumps ( reports ) <EOL> ff = py . process . ForkedFunc ( runforked ) <EOL> result = ff . waitfinish ( ) <EOL> if result . retval is not None : <EOL> return ipickle . loads ( result . retval ) <EOL> else : <EOL> if result . exitstatus == EXITSTATUS_TESTEXIT : <EOL> py . test . exit ( "<STR_LIT>" % ( item , ) ) <EOL> return [ report_process_crash ( item , result ) ] <EOL> def report_process_crash ( item , result ) : <EOL> path , lineno = item . _getfslineno ( ) <EOL> info = "<STR_LIT>" % ( <EOL> path , lineno , result . signal ) <EOL> return ItemTestReport ( item , excinfo = info , when = "<STR_LIT>" ) <EOL> class BaseReport ( object ) : <EOL> def __repr__ ( self ) : <EOL> l = [ "<STR_LIT>" % ( key , value ) <EOL> for key , value in self . __dict__ . items ( ) ] <EOL> return "<STR_LIT>" % ( self . __class__ . __name__ , "<STR_LIT:U+0020>" . join ( l ) , ) <EOL> def toterminal ( self , out ) : <EOL> longrepr = self . longrepr <EOL> if hasattr ( longrepr , '<STR_LIT>' ) : <EOL> longrepr . toterminal ( out ) <EOL> else : <EOL> out . line ( str ( longrepr ) ) <EOL> class ItemTestReport ( BaseReport ) : <EOL> failed = passed = skipped = False <EOL> def __init__ ( self , item , excinfo = None , when = None ) : <EOL> self . item = item <EOL> self . when = when <EOL> if item and when != "<STR_LIT>" : <EOL> self . keywords = item . readkeywords ( ) <EOL> else : <EOL> self . keywords = { } <EOL> if not excinfo : <EOL> self . passed = True <EOL> self . shortrepr = "<STR_LIT:.>" <EOL> else : <EOL> if not isinstance ( excinfo , py . code . ExceptionInfo ) : <EOL> self . failed = True <EOL> shortrepr = "<STR_LIT:?>" <EOL> longrepr = excinfo <EOL> elif excinfo . errisinstance ( Skipped ) : <EOL> self . skipped = True <EOL> shortrepr = "<STR_LIT:s>" <EOL> longrepr = self . item . _repr_failure_py ( excinfo ) <EOL> else : <EOL> self . failed = True <EOL> shortrepr = self . item . shortfailurerepr <EOL> if self . when == "<STR_LIT>" : <EOL> longrepr = self . item . repr_failure ( excinfo ) <EOL> else : <EOL> longrepr = self . item . _repr_failure_py ( excinfo ) <EOL> shortrepr = shortrepr . lower ( ) <EOL> self . shortrepr = shortrepr <EOL> self . longrepr = longrepr <EOL> def __repr__ ( self ) : <EOL> status = ( self . passed and "<STR_LIT>" or <EOL> self . skipped and "<STR_LIT>" or <EOL> self . failed and "<STR_LIT>" or <EOL> "<STR_LIT>" ) <EOL> l = [ repr ( self . item . name ) , "<STR_LIT>" % self . when , "<STR_LIT>" % status , ] <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> l . append ( "<STR_LIT>" % self . node . gateway . id ) <EOL> info = "<STR_LIT:U+0020>" . join ( map ( str , l ) ) <EOL> return "<STR_LIT>" % info <EOL> def getnode ( self ) : <EOL> return self . item <EOL> class CollectReport ( BaseReport ) : <EOL> skipped = failed = passed = False <EOL> def __init__ ( self , collector , result , excinfo = None ) : <EOL> self . collector = collector <EOL> if not excinfo : <EOL> self . passed = True <EOL> self . result = result <EOL> else : <EOL> self . longrepr = self . collector . _repr_failure_py ( excinfo ) <EOL> if excinfo . errisinstance ( Skipped ) : <EOL> self . skipped = True <EOL> self . reason = str ( excinfo . value ) <EOL> else : <EOL> self . failed = True <EOL> def getnode ( self ) : <EOL> return self . collector <EOL> class TeardownErrorReport ( BaseReport ) : <EOL> skipped = passed = False <EOL> failed = True <EOL> when = "<STR_LIT>" <EOL> def __init__ ( self , excinfo ) : <EOL> self . longrepr = excinfo . getrepr ( funcargs = True ) <EOL> class SetupState ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> self . stack = [ ] <EOL> self . _finalizers = { } <EOL> def addfinalizer ( self , finalizer , colitem ) : <EOL> """<STR_LIT>""" <EOL> assert callable ( finalizer ) <EOL> self . _finalizers . setdefault ( colitem , [ ] ) . append ( finalizer ) <EOL> def _pop_and_teardown ( self ) : <EOL> colitem = self . stack . pop ( ) <EOL> self . _teardown_with_finalization ( colitem ) <EOL> def _callfinalizers ( self , colitem ) : <EOL> finalizers = self . _finalizers . pop ( colitem , None ) <EOL> while finalizers : <EOL> fin = finalizers . pop ( ) <EOL> fin ( ) <EOL> def _teardown_with_finalization ( self , colitem ) : <EOL> self . _callfinalizers ( colitem ) <EOL> if colitem : <EOL> colitem . teardown ( ) <EOL> for colitem in self . _finalizers : <EOL> assert colitem is None or colitem in self . stack <EOL> def teardown_all ( self ) : <EOL> while self . stack : <EOL> self . _pop_and_teardown ( ) <EOL> self . _teardown_with_finalization ( None ) <EOL> assert not self . _finalizers <EOL> def teardown_exact ( self , item ) : <EOL> if item == self . stack [ - <NUM_LIT:1> ] : <EOL> self . _pop_and_teardown ( ) <EOL> else : <EOL> self . _callfinalizers ( item ) <EOL> def prepare ( self , colitem ) : <EOL> """<STR_LIT>""" <EOL> needed_collectors = colitem . listchain ( ) <EOL> while self . stack : <EOL> if self . stack == needed_collectors [ : len ( self . stack ) ] : <EOL> break <EOL> self . _pop_and_teardown ( ) <EOL> for col in needed_collectors [ len ( self . stack ) : ] : <EOL> col . setup ( ) <EOL> self . stack . append ( col ) </s>
