По сути, мне приходится повторно инициализировать содержимое набора тестов в рамках циклического запуска всего набора тестов. Я обнаружил, что не могу просто повторно вызывать один и тот же набор тестов, итеративно, поэтому я повторно инициализирую его.
Прежде чем войти в цикл, у меня есть список тестов my_tests код>.
Код: Выделить всё
runner = unittest.TextTestRunner()
my_suite = unittest.TestSuite(my_tests)
for i in range(2):
result = runner.run(my_suite)
print(f"{i} Number of tests, after running tests: suite suite length {my_suite.countTestCases()} test object {my_tests}")
unittest.registerResult(result)
# Empty test suite and re-add tests
my_suite._tests = []
print(my_suite.__dict__)
my_suite.addTests(my_tests)
print(my_suite.__dict__)
print(f"{i} Number of tests, after reinitialising suite: suite length {my_suite.countTestCases()} test object {my_tests}")
Код: Выделить всё
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
0 Number of tests, after running tests: suite length 1 test object []
{'_tests': [], '_removed_tests': 1}
{'_tests': [], '_removed_tests': 1}
0 Number of tests, after reinitilising suite:suite length 2 test object []
.
----------------------------------------------------------------------
Ran 1 test in 0.000s
OK
1 Number of tests, after running tests: suite length 2 test object []
{'_tests': [], '_removed_tests': 2}
{'_tests': [], '_removed_tests': 2}
1 Number of tests, after reinitilising suite:suite length 3 test object []
Я попытался и преуспел в решении этой проблемы с помощью следующего:< /p>
Я добавил:
Код: Выделить всё
my_suite.removed_tests = 0
Я действительно просто не понимаю, почему Remove_test count повлияет на поведение добавления тестов в набор, который, как сообщается, пуст?
Подробнее здесь: https://stackoverflow.com/questions/790 ... test-suite