mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-05-02 12:26:02 -04:00
Skip unit tests which require optional dependencies (#9031)
If we are lacking an optional dependency, skip the tests that rely on it.
This commit is contained in:
parent
eee3c3c52f
commit
8d3d264052
7 changed files with 91 additions and 14 deletions
|
@ -20,7 +20,7 @@ import hmac
|
|||
import inspect
|
||||
import logging
|
||||
import time
|
||||
from typing import Dict, Iterable, Optional, Tuple, Type, TypeVar, Union
|
||||
from typing import Callable, Dict, Iterable, Optional, Tuple, Type, TypeVar, Union
|
||||
|
||||
from mock import Mock, patch
|
||||
|
||||
|
@ -736,3 +736,29 @@ def override_config(extra_config):
|
|||
return func
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
TV = TypeVar("TV")
|
||||
|
||||
|
||||
def skip_unless(condition: bool, reason: str) -> Callable[[TV], TV]:
|
||||
"""A test decorator which will skip the decorated test unless a condition is set
|
||||
|
||||
For example:
|
||||
|
||||
class MyTestCase(TestCase):
|
||||
@skip_unless(HAS_FOO, "Cannot test without foo")
|
||||
def test_foo(self):
|
||||
...
|
||||
|
||||
Args:
|
||||
condition: If true, the test will be skipped
|
||||
reason: the reason to give for skipping the test
|
||||
"""
|
||||
|
||||
def decorator(f: TV) -> TV:
|
||||
if not condition:
|
||||
f.skip = reason # type: ignore
|
||||
return f
|
||||
|
||||
return decorator
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue