How to get Python unittest skipped result as Failed

Viewed 23

When running test_B , how do I check and skip my test_B when my TextTestRunner pass_result variable keep getting pass when my test_A is actually being skipped? Isit possible to set TextTestRunner to show skipped result as failed instead of passing result?

import unittest

class TestStringResult(unittest.TestCase):

    def test_A(self):
        missing = 1;
        if (missing):
            raise unittest.SkipTest('Required information is missing') 

    def test_B(self):
        pass_result =  unittest.TextTestRunner().run(TestStringResult('test_A')) 
        if not (pass_result):
            raise unittest.SkipTest('test_A has been skipped')
        print('test_A runs smoothly')
            
if __name__ == '__main__':
    unittest.main()

This is the output I am currently getting. :

test_B(__main__.TestStringResult) ... s
----------------------------------------------------------------------  
Ran 1 test in 0.074s

OK (skipped=1) 
test_A runs smoothly ok
---------------------------------------------------------------------- 
Ran 1 test in 0.089s

OK
0 Answers
Related