Reputation: 4352
I am running a command(testcases) in a for loop. When a test step fails in a test case, it aborts the rest of the test steps and exits. Because of this my for loop also exits midway. I don't have control over how the tests behave but I want to continue to run the for loop for the rest of the test cases. How can I achieve this? As of now I dont have a return value for the command that is used to run the tests.
Update: Hello all, Thank you for your replies. Sorry I should have posted my code earlier. Here it is... I have written as shell script:
for file in `ls *.xml`; do
testrunner.sh -j -a -f"output" $file
done
I will try the suggestions posted by you all and post my comments. Thanks
Upvotes: 0
Views: 203
Reputation: 1719
What do you mean by a common exits? If you mean it will throw an Exception, you could probably use continue
within try
and except
block to make the for loop keep going after the Exception.
Example:
for i in range(1,10):
print i
try:
if i == 4:
raise NameError
except NameError:
continue
This code will print out 1 to 9 even if there is an Error raised at i=4
.
Hope this helps.
Upvotes: 1
Reputation: 76715
Probably the failed test is raising an exception. You need to learn how exceptions work, and put a try:
block around the test code to catch the exception and allow the script to continue.
Here's a web page you could study: http://www.penzilla.net/tutorials/python/exceptions/
Upvotes: 0