|
9 | 9 | from .exceptions import KnownFailureDidNotFailTest |
10 | 10 |
|
11 | 11 |
|
12 | | -def skipif(skip_condition, *args, **kwargs): |
13 | | - if isinstance(skip_condition, bool) and 'reason' not in kwargs: |
14 | | - raise ValueError("you need to specify reason=STRING " |
15 | | - "when using booleans as conditions.") |
16 | | - |
17 | | - def skip_decorator(func): |
18 | | - import inspect |
19 | | - |
20 | | - def skipper(*_args, **_kwargs): |
21 | | - condition, msg = skip_condition, kwargs.get('reason') # local copy |
22 | | - if isinstance(condition, six.string_types): |
23 | | - globs = {'os': os, 'sys': sys} |
24 | | - try: |
25 | | - globs.update(func.__globals__) |
26 | | - except AttributeError: |
27 | | - globs.update(func.func_globals) |
28 | | - if msg is None: |
29 | | - msg = condition |
30 | | - condition = eval(condition, globs) |
31 | | - else: |
32 | | - condition = bool(condition) |
33 | | - |
34 | | - if condition: |
35 | | - skip(msg) |
36 | | - else: |
37 | | - return func(*_args, **_kwargs) |
38 | | - |
39 | | - if inspect.isclass(func): |
40 | | - setup = getattr(func, 'setup_class', classmethod(lambda _: None)) |
41 | | - setup = skip_decorator(setup.__func__) |
42 | | - setup = setup.__get__(func) |
43 | | - setattr(func, 'setup_class', setup) |
44 | | - return func |
45 | | - |
46 | | - return copy_metadata(func, skipper) |
47 | | - |
48 | | - return skip_decorator |
49 | | - |
50 | | - |
51 | 12 | def knownfailureif(fail_condition, msg=None, known_exception_class=None): |
52 | 13 | # based on numpy.testing.dec.knownfailureif |
53 | 14 | if msg is None: |
|
0 commit comments