Есть ли метод / свойство / var, чтобы получить список пропущенных тестов в python3 unittest? - PullRequest
0 голосов
/ 02 октября 2018

У меня есть несколько тестов в классе unittest.Testcase.Я пропускаю пару из них.В конце прогона я могу получить список пропущенных тестов?

1 Ответ

0 голосов
/ 02 октября 2018

Все пропущенные тесты хранятся в виде кортежей по именам в списке skipped в атрибуте result объекта TestProgram, который unittest.main() возвращает:

import unittest
import sys

class MyTestCase(unittest.TestCase):
    @unittest.skip("I don't want to do it")
    def test_nothing(self):
        self.fail("shouldn't happen")

    def test_something(self):
        self.assertTrue(True)

test = unittest.main(exit=False) # do not exit after testing is done
sys.stdout.flush() # flush stdout so that the following output will be at the end
for name, reason in test.result.skipped:
    print(name, reason)

Это выводит:

s.
----------------------------------------------------------------------
Ran 2 tests in 0.000s

OK (skipped=1)
test_nothing (__main__.MyTestCase) I don't want to do it
...