blob: 66a3cd6430da337a0593b8bead4e51f9e68740a2 [file] [log] [blame]
Alex Gaynor5951f462014-11-16 09:08:42 -08001# This file is dual licensed under the terms of the Apache License, Version
2# 2.0, and the BSD License. See the LICENSE file in the root of this repository
3# for complete details.
Alex Gaynorc37feed2014-03-08 08:32:56 -08004
5from __future__ import absolute_import, division, print_function
6
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -06007import pytest
8
Alex Gaynorb8b1d722016-03-19 16:47:30 -04009from cryptography.hazmat.backends.openssl import backend as openssl_backend
Alex Gaynor7aab8b42014-10-23 11:01:25 -070010
Alex Gaynorf9b3b152017-05-20 18:36:19 -070011from .utils import check_backend_support, skip_if_empty
Paul Kehrer34c075e2014-01-13 21:52:08 -050012
13
Alex Gaynorb8b1d722016-03-19 16:47:30 -040014def pytest_report_header(config):
Alex Gaynore85797b2016-03-19 16:51:05 -040015 return "OpenSSL: {0}".format(openssl_backend.openssl_version_text())
Alex Gaynorb8b1d722016-03-19 16:47:30 -040016
Alex Gaynor59303052016-03-19 16:48:18 -040017
Paul Kehrer34c075e2014-01-13 21:52:08 -050018def pytest_generate_tests(metafunc):
Paul Kehreraed9e172014-01-19 12:09:27 -060019 if "backend" in metafunc.fixturenames:
Paul Kehrerf93d8242014-10-23 12:07:20 -070020 filtered_backends = []
Alex Gaynor9bbd4902015-07-01 22:26:28 -040021 required_interfaces = [
Alex Gaynorf9b3b152017-05-20 18:36:19 -070022 mark.kwargs["interface"]
23 for mark in metafunc.function.requires_backend_interface
Alex Gaynor9bbd4902015-07-01 22:26:28 -040024 ]
Alex Gaynorf9b3b152017-05-20 18:36:19 -070025 if all(
26 isinstance(openssl_backend, iface) for iface in required_interfaces
27 ):
28 filtered_backends.append(openssl_backend)
Paul Kehrerf93d8242014-10-23 12:07:20 -070029
Paul Kehrer902d8cf2014-10-25 12:22:10 -070030 # If you pass an empty list to parametrize Bad Things(tm) happen
31 # as of pytest 2.6.4 when the test also has a parametrize decorator
32 skip_if_empty(filtered_backends, required_interfaces)
33
34 metafunc.parametrize("backend", filtered_backends)
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060035
36
37@pytest.mark.trylast
38def pytest_runtest_setup(item):
Paul Kehrer60fc8da2013-12-26 20:19:34 -060039 check_backend_support(item)
Paul Kehrer34c075e2014-01-13 21:52:08 -050040
41
42def pytest_addoption(parser):
43 parser.addoption(
44 "--backend", action="store", metavar="NAME",
45 help="Only run tests matching the backend NAME."
46 )