blob: c21f4dcc65a8aa924460e818af69b1f91192618a [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 Gaynor133a1792017-06-03 20:38:22 -040011from .utils import check_backend_support
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
Alex Gaynor133a1792017-06-03 20:38:22 -040018@pytest.fixture()
19def backend(request):
20 required_interfaces = [
21 mark.kwargs["interface"]
22 for mark in request.node.get_marker("requires_backend_interface")
23 ]
24 if all(
25 isinstance(openssl_backend, iface) for iface in required_interfaces
26 ):
27 return openssl_backend
28 pytest.skip(
29 "OpenSSL doesn't implement required interfaces: {0}".format(
30 required_interfaces
31 )
32 )
Paul Kehrer7e4bc6d2013-12-24 22:23:53 -060033
34
35@pytest.mark.trylast
36def pytest_runtest_setup(item):
Paul Kehrer60fc8da2013-12-26 20:19:34 -060037 check_backend_support(item)
Paul Kehrer34c075e2014-01-13 21:52:08 -050038
39
40def pytest_addoption(parser):
41 parser.addoption(
42 "--backend", action="store", metavar="NAME",
43 help="Only run tests matching the backend NAME."
44 )