2👍
✅
Here is how I’d do it:
- Have a global variable called
test_condition_a = False
shared among test cases. - Try/catch assert in
test_a
and catch the exception when it fails so that you can settest_condition_a = True
before the test exits. - Use
@unittest.skipIf(test_condition_a)
on all other test cases that you want run only iftest_a
fails.
EDIT On second thought, the above is not going to work as the test order is random. Your best bet would be to do something like this
class Test(TestCase):
def setUp(self):
...
@unittest.skip("Skip by default")
def testB(self):
#test code
def testA(self):
try:
#test code
return True
except Error:
return False
def testA_then_B(self):
if (self.testA()):
self.testB()
Source:stackexchange.com