diff options
Diffstat (limited to 'tests/conftest.py')
-rw-r--r-- | tests/conftest.py | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/tests/conftest.py b/tests/conftest.py index 20926024..9dc37d38 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -17,7 +17,7 @@ import pytest from cryptography.hazmat.backends import _available_backends -from .utils import check_backend_support, select_backends +from .utils import check_backend_support, select_backends, skip_if_empty def pytest_generate_tests(metafunc): @@ -25,22 +25,29 @@ def pytest_generate_tests(metafunc): selected_backends = select_backends(names, _available_backends()) if "backend" in metafunc.fixturenames: - metafunc.parametrize("backend", selected_backends) + filtered_backends = [] + for backend in selected_backends: + try: + required = metafunc.function.requires_backend_interface + except AttributeError: + # function does not have requires_backend_interface decorator + filtered_backends.append(backend) + else: + required_interfaces = tuple( + mark.kwargs["interface"] for mark in required + ) + if isinstance(backend, required_interfaces): + filtered_backends.append(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.mark.trylast def pytest_runtest_setup(item): - required = item.keywords.get("requires_backend_interface") - if required is not None and "backend" in item.funcargs: - required_interfaces = tuple( - mark.kwargs["interface"] for mark in required - ) - if not isinstance(item.funcargs["backend"], required_interfaces): - pytest.skip("{0} backend does not support {1}".format( - item.funcargs["backend"], - ", ".join(iface.__name__ for iface in required_interfaces) - )) - check_backend_support(item) |