Да, есть. Чтобы заставить его работать, мне удалось объединить методы из ответов на эти два вопроса:
Python, unittest: Можно ли сделать TestRunner полностью тихим?
argparse и unittest python
Вы можете раскомментировать тест test_should_fail()
, чтобы проверить, что происходит, когда тест не проходит.
# mymodule.py
def myfunc():
return True
import unittest
import os
class TestMyFunc(unittest.TestCase):
def test_myfunc(self):
self.assertEqual(myfunc(), True)
# def test_should_fail(self):
# self.assertEqual(True, False)
if __name__ == '__main__':
alltests = unittest.TestLoader().loadTestsFromTestCase(TestMyFunc)
runner = unittest.TextTestRunner(stream=open(os.devnull, 'w'))
result = runner.run(alltests)
if len(result.failures) or len(result.errors):
print('There were failures or errors.')