add mark that allows us to do skip tests on backends via decorators
diff --git a/tests/conftest.py b/tests/conftest.py
index e059b63..d8ab581 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -4,7 +4,7 @@
HMACBackend, CipherBackend, HashBackend
)
-from .utils import check_for_iface
+from .utils import check_for_iface, supported_by_backend_skip
def pytest_generate_tests(metafunc):
@@ -19,3 +19,4 @@
check_for_iface("hmac", HMACBackend, item)
check_for_iface("cipher", CipherBackend, item)
check_for_iface("hash", HashBackend, item)
+ supported_by_backend_skip(item)
diff --git a/tests/test_utils.py b/tests/test_utils.py
index a65091f..b347efd 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -20,7 +20,8 @@
from .utils import (
load_nist_vectors, load_vectors_from_file, load_cryptrec_vectors,
- load_openssl_vectors, load_hash_vectors, check_for_iface
+ load_openssl_vectors, load_hash_vectors, check_for_iface,
+ supported_by_backend_skip
)
@@ -41,6 +42,36 @@
check_for_iface("fake_name", FakeInterface, item)
+def test_supported_by_backend_skip():
+ supported = pretend.stub(
+ kwargs={"only_if": lambda backend: False, "skip_message": "Nope"}
+ )
+ item = pretend.stub(keywords={"supported": supported},
+ funcargs={"backend": True})
+ with pytest.raises(pytest.skip.Exception) as exc_info:
+ supported_by_backend_skip(item)
+ assert exc_info.value.args[0] == "Nope"
+
+
+def test_supported_by_backend_no_skip():
+ supported = pretend.stub(
+ kwargs={"only_if": lambda backend: True, "skip_message": "Nope"}
+ )
+ item = pretend.stub(keywords={"supported": supported},
+ funcargs={"backend": True})
+ assert supported_by_backend_skip(item) is None
+
+
+def test_supported_by_backend_skip_no_backend():
+ supported = pretend.stub(
+ kwargs={"only_if": "notalambda", "skip_message": "Nope"}
+ )
+ item = pretend.stub(keywords={"supported": supported},
+ funcargs={})
+ with pytest.raises(TypeError):
+ supported_by_backend_skip(item)
+
+
def test_load_nist_vectors():
vector_data = textwrap.dedent("""
# CAVS 11.1
diff --git a/tests/utils.py b/tests/utils.py
index 82021a5..113488d 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -24,6 +24,16 @@
))
+def supported_by_backend_skip(item):
+ supported = item.keywords.get("supported")
+ if supported and "backend" in item.funcargs:
+ if not supported.kwargs["only_if"](item.funcargs["backend"]):
+ pytest.skip(supported.kwargs["skip_message"])
+ elif supported:
+ raise TypeError("This mark is only available on methods that take a "
+ "backend")
+
+
def load_vectors_from_file(filename, loader):
base = os.path.join(
os.path.dirname(__file__), "hazmat", "primitives", "vectors",