<s> """<STR_LIT>""" <EOL> import py <EOL> import sys <EOL> def pytest_pycollect_makeitem ( collector , name , obj ) : <EOL> if '<STR_LIT>' not in sys . modules : <EOL> return <EOL> if py . std . inspect . isclass ( obj ) and issubclass ( obj , py . std . unittest . TestCase ) : <EOL> return UnitTestCase ( name , parent = collector ) <EOL> class UnitTestCase ( py . test . collect . Class ) : <EOL> def collect ( self ) : <EOL> return [ UnitTestCaseInstance ( "<STR_LIT>" , self ) ] <EOL> def setup ( self ) : <EOL> pass <EOL> def teardown ( self ) : <EOL> pass <EOL> _dummy = object ( ) <EOL> class UnitTestCaseInstance ( py . test . collect . Instance ) : <EOL> def collect ( self ) : <EOL> loader = py . std . unittest . TestLoader ( ) <EOL> names = loader . getTestCaseNames ( self . obj . __class__ ) <EOL> l = [ ] <EOL> for name in names : <EOL> callobj = getattr ( self . obj , name ) <EOL> if callable ( callobj ) : <EOL> l . append ( UnitTestFunction ( name , parent = self ) ) <EOL> return l <EOL> def _getobj ( self ) : <EOL> x = self . parent . obj <EOL> return self . parent . obj ( methodName = '<STR_LIT>' ) <EOL> class UnitTestFunction ( py . test . collect . Function ) : <EOL> def __init__ ( self , name , parent , args = ( ) , obj = _dummy , sort_value = None ) : <EOL> super ( UnitTestFunction , self ) . __init__ ( name , parent ) <EOL> self . _args = args <EOL> if obj is not _dummy : <EOL> self . _obj = obj <EOL> self . _sort_value = sort_value <EOL> if hasattr ( self . parent , '<STR_LIT>' ) : <EOL> self . parent . newinstance ( ) <EOL> self . obj = self . _getobj ( ) <EOL> def runtest ( self ) : <EOL> target = self . obj <EOL> args = self . _args <EOL> target ( * args ) <EOL> def setup ( self ) : <EOL> instance = self . obj . im_self <EOL> instance . setUp ( ) <EOL> def teardown ( self ) : <EOL> instance = self . obj . im_self <EOL> instance . tearDown ( ) <EOL> def test_simple_unittest ( testdir ) : <EOL> testpath = testdir . makepyfile ( """<STR_LIT>""" ) <EOL> reprec = testdir . inline_run ( testpath ) <EOL> assert reprec . matchreport ( "<STR_LIT>" ) . passed <EOL> assert reprec . matchreport ( "<STR_LIT>" ) . failed <EOL> def test_setup ( testdir ) : <EOL> testpath = testdir . makepyfile ( test_two = """<STR_LIT>""" ) <EOL> reprec = testdir . inline_run ( testpath ) <EOL> rep = reprec . matchreport ( "<STR_LIT>" ) <EOL> assert rep . passed <EOL> def test_new_instances ( testdir ) : <EOL> testpath = testdir . makepyfile ( """<STR_LIT>""" ) <EOL> reprec = testdir . inline_run ( testpath ) <EOL> reprec . assertoutcome ( passed = <NUM_LIT:2> ) <EOL> def test_teardown ( testdir ) : <EOL> testpath = testdir . makepyfile ( test_three = """<STR_LIT>""" ) <EOL> reprec = testdir . inline_run ( testpath ) <EOL> passed , skipped , failed = reprec . countoutcomes ( ) <EOL> print "<STR_LIT>" , passed , skipped , failed <EOL> assert failed == <NUM_LIT:0> , failed <EOL> assert passed == <NUM_LIT:2> <EOL> assert passed + skipped + failed == <NUM_LIT:2> </s>
