I am running a test and if it fails i want to go to the previous test and run the same test until it passes. Can someone let me know how to do it in Jython, if possible.
You should look at using test suite logic in SOAtest - you can set up tests that run until they pass without needing to write any scripts.
Take a look at the post found here for reference. Test flow logic!
To clarify an earlier comment, the test suite editor has an option to setup a "While pass/fail" loop. This is specifically intended to accomplish running a test repeatedly until it passes (or fails). Please check the SOAtest User's Guide for details.