aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorPaul Kehrer <paul.l.kehrer@gmail.com>2014-01-13 21:52:08 -0500
committerPaul Kehrer <paul.l.kehrer@gmail.com>2014-01-13 21:52:08 -0500
commit34c075e6f331d146a617417e646170e8847c39e4 (patch)
tree5a44fdf1fcb41d082b1103753c832242081b7280 /tests
parentf290f7d92d7608c6286b92ed235fdf4259627a5a (diff)
downloadcryptography-34c075e6f331d146a617417e646170e8847c39e4.tar.gz
cryptography-34c075e6f331d146a617417e646170e8847c39e4.tar.bz2
cryptography-34c075e6f331d146a617417e646170e8847c39e4.zip
support --backend as a pytest flag to limit to one backend for testing
Diffstat (limited to 'tests')
-rw-r--r--tests/conftest.py14
-rw-r--r--tests/test_utils.py23
-rw-r--r--tests/utils.py10
3 files changed, 45 insertions, 2 deletions
diff --git a/tests/conftest.py b/tests/conftest.py
index 1d9f96ed..5cc30428 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -5,7 +5,12 @@ from cryptography.hazmat.backends.interfaces import (
HMACBackend, CipherBackend, HashBackend
)
-from .utils import check_for_iface, check_backend_support
+from .utils import check_for_iface, check_backend_support, modify_backend_list
+
+
+def pytest_generate_tests(metafunc):
+ name = metafunc.config.getoption("--backend")
+ modify_backend_list(name, _ALL_BACKENDS)
@pytest.fixture(params=_ALL_BACKENDS)
@@ -19,3 +24,10 @@ def pytest_runtest_setup(item):
check_for_iface("cipher", CipherBackend, item)
check_for_iface("hash", HashBackend, item)
check_backend_support(item)
+
+
+def pytest_addoption(parser):
+ parser.addoption(
+ "--backend", action="store", metavar="NAME",
+ help="Only run tests matching the backend NAME."
+ )
diff --git a/tests/test_utils.py b/tests/test_utils.py
index e3e53d63..e8037c1d 100644
--- a/tests/test_utils.py
+++ b/tests/test_utils.py
@@ -21,7 +21,7 @@ import pytest
from .utils import (
load_nist_vectors, load_vectors_from_file, load_cryptrec_vectors,
load_openssl_vectors, load_hash_vectors, check_for_iface,
- check_backend_support
+ check_backend_support, modify_backend_list
)
@@ -29,6 +29,27 @@ class FakeInterface(object):
pass
+def test_modify_backend_list_leave_one():
+ b1 = pretend.stub(name="b1")
+ b2 = pretend.stub(name="b2")
+ b3 = pretend.stub(name="b3")
+ backends = [b1, b2, b3]
+ name = "b2"
+ modify_backend_list(name, backends)
+ assert len(backends) == 1
+ assert backends[0] == b2
+
+
+def test_modify_backend_list_error_none():
+ b1 = pretend.stub(name="b1")
+ b2 = pretend.stub(name="b2")
+ b3 = pretend.stub(name="b3")
+ backends = [b1, b2, b3]
+ name = "back!"
+ with pytest.raises(ValueError):
+ modify_backend_list(name, backends)
+
+
def test_check_for_iface():
item = pretend.stub(keywords=["fake_name"], funcargs={"backend": True})
with pytest.raises(pytest.skip.Exception) as exc_info:
diff --git a/tests/utils.py b/tests/utils.py
index 693a0c8f..343f3efe 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -16,6 +16,16 @@ import os
import pytest
+def modify_backend_list(name, all_backends):
+ if name is not None:
+ backends = list(all_backends)
+ for backend in backends:
+ if backend.name != name:
+ all_backends.remove(backend)
+ if len(all_backends) == 0:
+ raise ValueError("No backends selected for testing")
+
+
def check_for_iface(name, iface, item):
if name in item.keywords and "backend" in item.funcargs:
if not isinstance(item.funcargs["backend"], iface):