blob: 00c44ca9db7251abd6653cd59ef728741b0e6111 [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 (
Paul Kehrer1277bc72014-01-28 17:09:59 -06005 HMACBackend, CipherBackend, HashBackend, PBKDF2HMACBackend
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -06006)
Alex Gaynorfcaf9762014-01-30 11:23:57 -08007from cryptography.hazmat.backends.multibackend import PrioritizedMultiBackend
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -06008
Paul Kehrerc421e632014-01-18 09:22:21 -06009from .utils import check_for_iface, check_backend_support, select_backends
Paul Kehrer34c075e2014-01-13 21:52:08 -050010
11
12def pytest_generate_tests(metafunc):
Paul Kehrerc421e632014-01-18 09:22:21 -060013 names = metafunc.config.getoption("--backend")
Alex Gaynorfcaf9762014-01-30 11:23:57 -080014 selected_backends = select_backends(
15 names, _ALL_BACKENDS + [PrioritizedMultiBackend(_ALL_BACKENDS)]
16 )
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060017
Paul Kehreraed9e172014-01-19 12:09:27 -060018 if "backend" in metafunc.fixturenames:
19 metafunc.parametrize("backend", selected_backends)
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060020
21
22@pytest.mark.trylast
23def pytest_runtest_setup(item):
Alex Gaynor2b3f9422013-12-24 21:55:24 -080024 check_for_iface("hmac", HMACBackend, item)
25 check_for_iface("cipher", CipherBackend, item)
26 check_for_iface("hash", HashBackend, item)
Paul Kehrer1277bc72014-01-28 17:09:59 -060027 check_for_iface("pbkdf2hmac", PBKDF2HMACBackend, item)
Paul Kehrer60fc8da2013-12-26 20:19:34 -060028 check_backend_support(item)
Paul Kehrer34c075e2014-01-13 21:52:08 -050029
30
31def pytest_addoption(parser):
32 parser.addoption(
33 "--backend", action="store", metavar="NAME",
34 help="Only run tests matching the backend NAME."
35 )