blob: 2092602416efc93db6250058b43951d1a00949bf [file] [log] [blame]
Alex Gaynorc37feed2014-03-08 08:32:56 -08001# Licensed under the Apache License, Version 2.0 (the "License");
2# you may not use this file except in compliance with the License.
3# You may obtain a copy of the License at
4#
5# http://www.apache.org/licenses/LICENSE-2.0
6#
7# Unless required by applicable law or agreed to in writing, software
8# distributed under the License is distributed on an "AS IS" BASIS,
9# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
10# implied.
11# See the License for the specific language governing permissions and
12# limitations under the License.
13
14from __future__ import absolute_import, division, print_function
15
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060016import pytest
17
Alex Stapleton01de3ef2014-03-16 16:42:47 +000018from cryptography.hazmat.backends import _available_backends
Alex Gaynor7aab8b42014-10-23 11:01:25 -070019
20from .utils import check_backend_support, select_backends
Paul Kehrer34c075e2014-01-13 21:52:08 -050021
22
23def pytest_generate_tests(metafunc):
Paul Kehrerc421e632014-01-18 09:22:21 -060024 names = metafunc.config.getoption("--backend")
Alex Stapleton01de3ef2014-03-16 16:42:47 +000025 selected_backends = select_backends(names, _available_backends())
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060026
Paul Kehreraed9e172014-01-19 12:09:27 -060027 if "backend" in metafunc.fixturenames:
28 metafunc.parametrize("backend", selected_backends)
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060029
30
31@pytest.mark.trylast
32def pytest_runtest_setup(item):
Alex Gaynor7aab8b42014-10-23 11:01:25 -070033 required = item.keywords.get("requires_backend_interface")
Alex Gaynor276ba5a2014-10-23 11:31:10 -070034 if required is not None and "backend" in item.funcargs:
Alex Gaynor055631d2014-10-23 11:25:51 -070035 required_interfaces = tuple(
Alex Gaynor2607ab52014-10-23 11:34:10 -070036 mark.kwargs["interface"] for mark in required
Alex Gaynor055631d2014-10-23 11:25:51 -070037 )
38 if not isinstance(item.funcargs["backend"], required_interfaces):
39 pytest.skip("{0} backend does not support {1}".format(
40 item.funcargs["backend"],
41 ", ".join(iface.__name__ for iface in required_interfaces)
42 ))
Alex Gaynor7aab8b42014-10-23 11:01:25 -070043
Paul Kehrer60fc8da2013-12-26 20:19:34 -060044 check_backend_support(item)
Paul Kehrer34c075e2014-01-13 21:52:08 -050045
46
47def pytest_addoption(parser):
48 parser.addoption(
49 "--backend", action="store", metavar="NAME",
50 help="Only run tests matching the backend NAME."
51 )