aboutsummaryrefslogtreecommitdiffstats
path: root/tests/conftest.py
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2014-10-25 17:34:55 -0700
committerAlex Gaynor <alex.gaynor@gmail.com>2014-10-25 17:34:55 -0700
commitd1f0c6621036bfb801066b2c34fe5bff6f234388 (patch)
treefa7c955afae211f032a492162664941e060ff77b /tests/conftest.py
parentdaca59235c6be9ae11044aa8bb14e137c0435dd2 (diff)
parent902d8cfd58de395748d71f449944faa9dbac8725 (diff)
downloadcryptography-d1f0c6621036bfb801066b2c34fe5bff6f234388.tar.gz
cryptography-d1f0c6621036bfb801066b2c34fe5bff6f234388.tar.bz2
cryptography-d1f0c6621036bfb801066b2c34fe5bff6f234388.zip
Merge pull request #1437 from reaperhulk/conftest-changes
filter backends during initial generation to elide tests entirely
Diffstat (limited to 'tests/conftest.py')
-rw-r--r--tests/conftest.py33
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)