aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/conftest.py34
-rw-r--r--tests/test_utils.py13
-rw-r--r--tests/utils.py9
3 files changed, 17 insertions, 39 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 66a3cd64..c21f4dcc 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -8,30 +8,28 @@ import pytest
from cryptography.hazmat.backends.openssl import backend as openssl_backend
-from .utils import check_backend_support, skip_if_empty
+from .utils import check_backend_support
def pytest_report_header(config):
return "OpenSSL: {0}".format(openssl_backend.openssl_version_text())
-def pytest_generate_tests(metafunc):
- if "backend" in metafunc.fixturenames:
- filtered_backends = []
- required_interfaces = [
- mark.kwargs["interface"]
- for mark in metafunc.function.requires_backend_interface
- ]
- if all(
- isinstance(openssl_backend, iface) for iface in required_interfaces
- ):
- filtered_backends.append(openssl_backend)
-
- # If you pass an empty list to parametrize Bad Things(tm) happen
- # as of pytest 2.6.4 when the test also has a parametrize decorator
- skip_if_empty(filtered_backends, required_interfaces)
-
- metafunc.parametrize("backend", filtered_backends)
+@pytest.fixture()
+def backend(request):
+ required_interfaces = [
+ mark.kwargs["interface"]
+ for mark in request.node.get_marker("requires_backend_interface")
+ ]
+ if all(
+ isinstance(openssl_backend, iface) for iface in required_interfaces
+ ):
+ return openssl_backend
+ pytest.skip(
+ "OpenSSL doesn't implement required interfaces: {0}".format(
+ required_interfaces
+ )
+ )
@pytest.mark.trylast
diff --git a/tests/test_utils.py b/tests/test_utils.py
index 1637ba5b..2b5a2af3 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -24,21 +24,10 @@ from .utils import (
load_hash_vectors, load_kasvs_dh_vectors,
load_kasvs_ecdh_vectors, load_nist_kbkdf_vectors, load_nist_vectors,
load_pkcs1_vectors, load_rsa_nist_vectors, load_vectors_from_file,
- load_x963_vectors, raises_unsupported_algorithm, skip_if_empty
+ load_x963_vectors, raises_unsupported_algorithm
)
-class FakeInterface(object):
- pass
-
-
-def test_skip_if_empty():
- with pytest.raises(pytest.skip.Exception):
- skip_if_empty([], [FakeInterface])
-
- skip_if_empty(["notempty"], [FakeInterface])
-
-
def test_check_backend_support_skip():
supported = pretend.stub(
kwargs={"only_if": lambda backend: False, "skip_message": "Nope"}
diff --git a/tests/utils.py b/tests/utils.py
index 44e16a57..136b0607 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -25,15 +25,6 @@ KeyedHashVector = collections.namedtuple(
)
-def skip_if_empty(backend_list, required_interfaces):
- if not backend_list:
- pytest.skip(
- "No backends provided supply the interface: {0}".format(
- ", ".join(iface.__name__ for iface in required_interfaces)
- )
- )
-
-
def check_backend_support(item):
supported = item.keywords.get("supported")
if supported and "backend" in item.funcargs: