conftest.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 import _available_backends
  7. from .utils import check_backend_support, select_backends, skip_if_empty
  8. def pytest_generate_tests(metafunc):
  9. if "backend" in metafunc.fixturenames:
  10. names = metafunc.config.getoption("--backend")
  11. selected_backends = select_backends(names, _available_backends())
  12. filtered_backends = []
  13. required = metafunc.function.requires_backend_interface
  14. required_interfaces = [
  15. mark.kwargs["interface"] for mark in required
  16. ]
  17. for backend in selected_backends:
  18. if all(
  19. isinstance(backend, iface) for iface in required_interfaces
  20. ):
  21. filtered_backends.append(backend)
  22. # If you pass an empty list to parametrize Bad Things(tm) happen
  23. # as of pytest 2.6.4 when the test also has a parametrize decorator
  24. skip_if_empty(filtered_backends, required_interfaces)
  25. metafunc.parametrize("backend", filtered_backends)
  26. @pytest.mark.trylast
  27. def pytest_runtest_setup(item):
  28. check_backend_support(item)
  29. def pytest_addoption(parser):
  30. parser.addoption(
  31. "--backend", action="store", metavar="NAME",
  32. help="Only run tests matching the backend NAME."
  33. )