bpo-41620: Return the result when the test is being skipped by Tabrizian · Pull Request #21944 · python/cpython
- The problem is that when I'm trying to collect test results if one of the tests is being skipped the error below pops up because
test_resultobject is None.
AttributeError: 'NoneType' object has no attribute 'testsRun'
import unittest import json class TestResultCollector(unittest.TestCase): @classmethod def setResult(cls, total, errors, failures): cls.total, cls.errors, cls.failures = \ total, errors, failures @classmethod def tearDownClass(cls): json_res = { 'total': cls.total, 'errors': cls.errors, 'failures': cls.failures } print(json.dumps(json_res)) def test1(self): self.assertTrue(True) def test2(self): self.assertTrue(True) def test3(self): self.assertTrue(True) @unittest.skip('Skip Test') def test4(self): self.assertTrue(True) def run(self, result=None): test_result = super().run(result) total = test_result.testsRun errors = len(test_result.errors) failures = len(test_result.failures) self.setResult(total, errors, failures) if __name__ == '__main__': unittest.main()
- I will add a unittest for this test case if you think this is a valid change. @iritkatriel