I have a testSuite in Python with several testCases.
If a testCase fails, testSuite continues with the next testCase. I would like to be able to stop testSuite when a testCase fails or be able to decide if the testSuite should continue or stop.
Once you are in a TestCase , the stop() method for the TestResult is not used when iterating through the tests. Somewhat related to your question, if you are using python 2.7, you can use the -f/--failfast flag when calling your test with python -m unittest . This will stop the test at the first failure. Thanks.
Alternate syntax for skipping test is using instance method skipTest() inside the test function.
A test case is the individual unit of testing. It checks for a specific response to a particular set of inputs. unittest provides a base class, TestCase , which may be used to create new test cases.
Use failfast=True it will stop running all tests if 1 fails in your test class
Example:
if __name__ == '__main__':
unittest.main(failfast=True)
None of the answers seem to touch on this part of your question:
... be able to decide if the testSuite should continue or stop.
You can override the run() method within your TestCase class and call the TestResult.stop() method to signal to the TestSuite to stop running tests.
class MyTestCase(unittest.TestCase):
def run(self, result=None):
if stop_test_condition():
result.stop()
return
super().run(result=result)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With