Make function raise SkipTest exception if skip_condition is true Parameters ---------- skip_condition : bool or callable Flag to determine whether to skip test. If the condition is a callable, it is used at runtime to dynamically make the decision. This is useful for
(skip_condition: bool, msg: Optional[str]=None)
| 12 | from typing import Optional |
| 13 | |
| 14 | def skipif(skip_condition: bool, msg: Optional[str]=None) -> MarkDecorator: |
| 15 | """Make function raise SkipTest exception if skip_condition is true |
| 16 | |
| 17 | Parameters |
| 18 | ---------- |
| 19 | |
| 20 | skip_condition : bool or callable |
| 21 | Flag to determine whether to skip test. If the condition is a |
| 22 | callable, it is used at runtime to dynamically make the decision. This |
| 23 | is useful for tests that may require costly imports, to delay the cost |
| 24 | until the test suite is actually executed. |
| 25 | msg : string |
| 26 | Message to give on raising a SkipTest exception. |
| 27 | |
| 28 | Returns |
| 29 | ------- |
| 30 | decorator : function |
| 31 | Decorator, which, when applied to a function, causes SkipTest |
| 32 | to be raised when the skip_condition was True, and the function |
| 33 | to be called normally otherwise. |
| 34 | """ |
| 35 | if msg is None: |
| 36 | msg = "Test skipped due to test condition." |
| 37 | |
| 38 | assert isinstance(skip_condition, bool) |
| 39 | return pytest.mark.skipif(skip_condition, reason=msg) |
| 40 | |
| 41 | |
| 42 | # A version with the condition set to true, common case just to attach a message |
no outgoing calls
no test coverage detected
searching dependent graphs…