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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -