File: case_analysis.py

package info (click to toggle)
pcs 0.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 16,148 kB
  • sloc: python: 238,810; xml: 20,833; ruby: 13,203; makefile: 1,595; sh: 484
file content (24 lines) | stat: -rw-r--r-- 854 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def _list2reason(test, exc_list):
    if exc_list and exc_list[-1][0] is test:
        return exc_list[-1][1]
    return None


def test_failed(test):
    # Borrowed from
    # https://stackoverflow.com/questions/4414234/getting-pythons-unittest-results-in-a-teardown-method/39606065#39606065
    # for Python versions 3.4 to 3.11
    # pylint: disable=protected-access
    if hasattr(test._outcome, "errors"):
        # Python 3.4 - 3.10 (These 2 methods have no side effects)
        result = test.defaultTestResult()
        test._feedErrorsToResult(result, test._outcome.errors)
    else:
        # Python 3.11+
        result = test._outcome.result
        if not hasattr(result, "errors") or not hasattr(result, "failures"):
            return None

    return _list2reason(test, result.errors) or _list2reason(
        test, result.failures
    )