File: suite_holder.py

package info (click to toggle)
python-pyclustering 0.10.1.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 11,128 kB
  • sloc: cpp: 38,888; python: 24,311; sh: 384; makefile: 105
file content (52 lines) | stat: -rwxr-xr-x 1,469 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""!

@brief Test suite storage

@authors Andrei Novikov (pyclustering@yandex.ru)
@date 2014-2020
@copyright BSD-3-Clause

"""


import sys
import time
import unittest


class suite_holder:
    def __init__(self):
        self.__suite = unittest.TestSuite()

    def get_suite(self):
        return self.__suite

    def run(self, rerun=2):
        print(self.__suite)
        result = unittest.TextTestRunner(stream=sys.stdout, verbosity=3).run(self.__suite)
        if result.wasSuccessful() is True:
            return result

        if len(result.errors) > 0:
            return result   # no need to restart in case of errors

        for attempt in range(rerun):
            time.sleep(1)   # sleep 1 second to change current time for random seed.

            print("\n======================================================================")
            print("Rerun failed tests (attempt: %d)." % (attempt + 1))
            print("----------------------------------------------------------------------")

            failure_suite = unittest.TestSuite()
            for failure in result.failures:
                failure_suite.addTest(failure[0])

            result = unittest.TextTestRunner(stream=sys.stdout, verbosity=3).run(failure_suite)
            if result.wasSuccessful() is True:
                return result

        return result

    @staticmethod
    def fill_suite(test_suite):
        pass;