python 자동화 테스트 캡처 장식기 사용

장식기:
def getImage(function):
    @wraps(function)
    def get_ErrImage(self,*args, **kwargs):      
        try:
            result = function(self,*args, **kwargs)
        except:
            timestr = time.strftime("%Y-%m-%d_%H_%M_%S")
            self.dr.get_screenshot_as_file('E:\\Appium\\Mailchat\\image\\getscreen\\%s %s.png' %
                                           (function.__name__timestr))
        else:
            logging.info (" %s  " %
                (function.__name__)
                )
        return result
    return get_ErrImage

사용 방법:
class myInitiate_addOppionTest(unittest.TestCase):

    def setUp(self):
        public.setUp.setUp(self)

    def tearDown(self):
        self.dr.quit()

    @getImage
    def test_myInitiate_addOppion(self):
        go_loginPage(self)   # 

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(myInitiate_addOppionTest)
    unittest.TextTestRunner(verbosity=2).run(suite)

좋은 웹페이지 즐겨찾기