conftest.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # 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.
  4. from __future__ import absolute_import, division, print_function
  5. import pytest
  6. from cryptography.hazmat.backends.openssl import backend as openssl_backend
  7. from .utils import (
  8. check_backend_support, load_wycheproof_tests, skip_if_wycheproof_none
  9. )
  10. def pytest_report_header(config):
  11. return "OpenSSL: {}".format(openssl_backend.openssl_version_text())
  12. def pytest_addoption(parser):
  13. parser.addoption("--wycheproof-root", default=None)
  14. def pytest_generate_tests(metafunc):
  15. if "wycheproof" in metafunc.fixturenames:
  16. wycheproof = metafunc.config.getoption("--wycheproof-root")
  17. skip_if_wycheproof_none(wycheproof)
  18. testcases = []
  19. marker = metafunc.definition.get_closest_marker("wycheproof_tests")
  20. for path in marker.args:
  21. testcases.extend(load_wycheproof_tests(wycheproof, path))
  22. metafunc.parametrize("wycheproof", testcases)
  23. @pytest.fixture()
  24. def backend(request):
  25. required_interfaces = [
  26. mark.kwargs["interface"]
  27. for mark in request.node.iter_markers("requires_backend_interface")
  28. ]
  29. if not all(
  30. isinstance(openssl_backend, iface) for iface in required_interfaces
  31. ):
  32. pytest.skip(
  33. "OpenSSL doesn't implement required interfaces: {}".format(
  34. required_interfaces
  35. )
  36. )
  37. check_backend_support(openssl_backend, request)
  38. return openssl_backend