From 8fa5d719a3c902ca9b6c9198229b7a67fecf8b8e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgorny@gentoo.org>
Date: Fri, 26 Nov 2021 16:12:16 +0100
Subject: [PATCH] Move cryptography-based imports into the fixture

Move the imports that require cryptography into the cert_factory
fixture.  This makes it possible to deselect these tests on systems
where cryptography cannot be installed.
---
 tests/conftest.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tests/conftest.py b/tests/conftest.py
index 076aeaf19..bab6ab3f5 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -27,7 +27,6 @@ from pip._internal.cli.main import main as pip_entry_point
 from pip._internal.locations import _USE_SYSCONFIG
 from pip._internal.utils.temp_dir import global_tempdir_manager
 from tests.lib import DATA_DIR, SRC_DIR, PipTestEnvironment, TestData
-from tests.lib.certs import make_tls_cert, serialize_cert, serialize_key
 from tests.lib.path import Path
 from tests.lib.server import MockServer as _MockServer
 from tests.lib.server import make_mock_server, server_running
@@ -535,6 +534,11 @@ def deprecated_python() -> bool:
 
 @pytest.fixture(scope="session")
 def cert_factory(tmpdir_factory: pytest.TempdirFactory) -> Callable[[], str]:
+    # Delay the import requiring cryptography in order to make it possible
+    # to deselect relevant tests on systems where cryptography cannot
+    # be installed.
+    from tests.lib.certs import make_tls_cert, serialize_cert, serialize_key
+
     def factory() -> str:
         """Returns path to cert/key file."""
         output_path = Path(str(tmpdir_factory.mktemp("certs"))) / "cert.pem"
-- 
2.34.1

