conftest.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. import pytest
  5. from cryptography.hazmat.backends.openssl import backend as openssl_backend
  6. from .utils import check_backend_support
  7. def pytest_configure(config):
  8. if config.getoption("--enable-fips"):
  9. openssl_backend._enable_fips()
  10. def pytest_report_header(config):
  11. return "\n".join(
  12. [
  13. "OpenSSL: {}".format(openssl_backend.openssl_version_text()),
  14. "FIPS Enabled: {}".format(openssl_backend._fips_enabled),
  15. ]
  16. )
  17. def pytest_addoption(parser):
  18. parser.addoption("--wycheproof-root", default=None)
  19. parser.addoption("--enable-fips", default=False)
  20. def pytest_runtest_setup(item):
  21. if openssl_backend._fips_enabled:
  22. for marker in item.iter_markers(name="skip_fips"):
  23. pytest.skip(marker.kwargs["reason"])
  24. @pytest.fixture()
  25. def backend(request):
  26. check_backend_support(openssl_backend, request)
  27. # Ensure the error stack is clear before the test
  28. errors = openssl_backend._consume_errors_with_text()
  29. assert not errors
  30. yield openssl_backend
  31. # Ensure the error stack is clear after the test
  32. errors = openssl_backend._consume_errors_with_text()
  33. assert not errors