blob: a9acb54a9ba2c3bdc8745cdccc1a25f7f9b22120 [file] [log] [blame]
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -06001import pytest
2
Alex Stapleton0d583732014-01-10 22:39:12 +00003from cryptography.hazmat.backends import _ALL_BACKENDS
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -06004from cryptography.hazmat.backends.interfaces import (
5 HMACBackend, CipherBackend, HashBackend
6)
7
Paul Kehrerc421e632014-01-18 09:22:21 -06008from .utils import check_for_iface, check_backend_support, select_backends
Paul Kehrer34c075e2014-01-13 21:52:08 -05009
10
11def pytest_generate_tests(metafunc):
Paul Kehrerc421e632014-01-18 09:22:21 -060012 names = metafunc.config.getoption("--backend")
Paul Kehreraed9e172014-01-19 12:09:27 -060013 selected_backends = select_backends(names, _ALL_BACKENDS)
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060014
Paul Kehreraed9e172014-01-19 12:09:27 -060015 if "backend" in metafunc.fixturenames:
16 metafunc.parametrize("backend", selected_backends)
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060017
18
19@pytest.mark.trylast
20def pytest_runtest_setup(item):
Alex Gaynor2b3f9422013-12-24 21:55:24 -080021 check_for_iface("hmac", HMACBackend, item)
22 check_for_iface("cipher", CipherBackend, item)
23 check_for_iface("hash", HashBackend, item)
Paul Kehrer60fc8da2013-12-26 20:19:34 -060024 check_backend_support(item)
Paul Kehrer34c075e2014-01-13 21:52:08 -050025
26
27def pytest_addoption(parser):
28 parser.addoption(
29 "--backend", action="store", metavar="NAME",
30 help="Only run tests matching the backend NAME."
31 )