blob: 49e178bc5d1f1883fd1eed89080556969ad597ca [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 Kehrer34c075e2014-01-13 21:52:08 -05008from .utils import check_for_iface, check_backend_support, modify_backend_list
9
10
Paul Kehrer098579e2014-01-14 10:26:44 -050011# copy all backends so we can mutate it.This variable is used in generate
12# tests to allow us to target a single backend without changing _ALL_BACKENDS
Paul Kehrer681e7a52014-01-14 10:48:56 -050013_DESIRED_BACKENDS = list(_ALL_BACKENDS)
Paul Kehrer098579e2014-01-14 10:26:44 -050014
15
Paul Kehrer34c075e2014-01-13 21:52:08 -050016def pytest_generate_tests(metafunc):
Paul Kehrer681e7a52014-01-14 10:48:56 -050017 global _DESIRED_BACKENDS
Paul Kehrer34c075e2014-01-13 21:52:08 -050018 name = metafunc.config.getoption("--backend")
Paul Kehrer681e7a52014-01-14 10:48:56 -050019 modify_backend_list(name, _DESIRED_BACKENDS)
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060020
21
Paul Kehrer681e7a52014-01-14 10:48:56 -050022@pytest.fixture(params=_DESIRED_BACKENDS)
Alex Stapleton0d583732014-01-10 22:39:12 +000023def backend(request):
24 return request.param
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060025
26
27@pytest.mark.trylast
28def pytest_runtest_setup(item):
Alex Gaynor2b3f9422013-12-24 21:55:24 -080029 check_for_iface("hmac", HMACBackend, item)
30 check_for_iface("cipher", CipherBackend, item)
31 check_for_iface("hash", HashBackend, item)
Paul Kehrer60fc8da2013-12-26 20:19:34 -060032 check_backend_support(item)
Paul Kehrer34c075e2014-01-13 21:52:08 -050033
34
35def pytest_addoption(parser):
36 parser.addoption(
37 "--backend", action="store", metavar="NAME",
38 help="Only run tests matching the backend NAME."
39 )