Failed Conditions
Pull Request — master (#1184)
by Lasse
01:48
created

bears.tests.generate_skip_decorator()   A

Complexity

Conditions 2

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 13
rs 9.4286
1
from unittest.case import skip, skipIf
2
3
4
def generate_skip_decorator(bear):
5
    """
6
    Creates a skip decorator for a `unittest` module test from a bear.
7
8
    `check_prerequisites` is used to determine a test skip.
9
10
    :param bear: The bear whose prerequisites determine the test skip.
11
    :return:     A decorator that skips the test if appropriate.
12
    """
13
    result = bear.check_prerequisites()
14
15
    return (skip(result) if isinstance(result, str)
16
            else skipIf(not result, '(No reason given.)'))
17