unit testing - Executing code only when a python unittest has failed -
i working on project has lot of selenium tests. tests run using python binding of selenium , python unittest. when tests fail unittest displays exception stack trace , error message. of tests not enough information debug problem. screenshot of browser , copy of browser log helpful.
so want is: if test fails, before closing selenium driver want take screenshot , save somewhere. need function teardown() should called when test fails. looked @ source code of unittest , specificaly testcase class , couldn't find anything. can help?
the stackoverflow community recommended adding try...except.. blocks around each test solution there hundreds of tests. cannot possible edit each one. looking general, non hacky way doing this. adding try..except.. blocks require me going through each test , copy/pasting try..except part or writing decorator , decorating each test. working in team other developers , don't want have long conversation why should decorate each test write , happen if don't.
p.s. know can take screenshot after every test , @ screenshots of failed tests. not point.
Comments
Post a Comment