From 903a175542c75392e798c631b97479eba62a7824 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Thu, 4 Sep 2025 11:34:37 +0530 Subject: [PATCH 1/4] allow tests to run without trustme --- tests/conftest.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 41ed907ea70..9d01e47c198 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -96,14 +96,14 @@ def blockbuster(request: pytest.FixtureRequest) -> Iterator[None]: @pytest.fixture -def tls_certificate_authority() -> trustme.CA: +def tls_certificate_authority() -> "trustme.CA": if not TRUSTME: pytest.xfail("trustme is not supported") return trustme.CA() @pytest.fixture -def tls_certificate(tls_certificate_authority: trustme.CA) -> trustme.LeafCert: +def tls_certificate(tls_certificate_authority: "trustme.CA") -> "trustme.LeafCert": return tls_certificate_authority.issue_cert( "localhost", "xn--prklad-4va.localhost", @@ -113,33 +113,33 @@ def tls_certificate(tls_certificate_authority: trustme.CA) -> trustme.LeafCert: @pytest.fixture -def ssl_ctx(tls_certificate: trustme.LeafCert) -> ssl.SSLContext: +def ssl_ctx(tls_certificate: "trustme.LeafCert") -> ssl.SSLContext: ssl_ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) tls_certificate.configure_cert(ssl_ctx) return ssl_ctx @pytest.fixture -def client_ssl_ctx(tls_certificate_authority: trustme.CA) -> ssl.SSLContext: +def client_ssl_ctx(tls_certificate_authority: "trustme.CA") -> ssl.SSLContext: ssl_ctx = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH) tls_certificate_authority.configure_trust(ssl_ctx) return ssl_ctx @pytest.fixture -def tls_ca_certificate_pem_path(tls_certificate_authority: trustme.CA) -> Iterator[str]: +def tls_ca_certificate_pem_path(tls_certificate_authority: "trustme.CA") -> Iterator[str]: with tls_certificate_authority.cert_pem.tempfile() as ca_cert_pem: yield ca_cert_pem @pytest.fixture -def tls_certificate_pem_path(tls_certificate: trustme.LeafCert) -> Iterator[str]: +def tls_certificate_pem_path(tls_certificate: "trustme.LeafCert") -> Iterator[str]: with tls_certificate.private_key_and_cert_chain_pem.tempfile() as cert_pem: yield cert_pem @pytest.fixture -def tls_certificate_pem_bytes(tls_certificate: trustme.LeafCert) -> bytes: +def tls_certificate_pem_bytes(tls_certificate: "trustme.LeafCert") -> bytes: return tls_certificate.cert_chain_pems[0].bytes() From 169aebf25898b315506e80b0447500058bd557c9 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Thu, 4 Sep 2025 11:38:37 +0530 Subject: [PATCH 2/4] add news --- CHANGES/11465.contrib.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 CHANGES/11465.contrib.rst diff --git a/CHANGES/11465.contrib.rst b/CHANGES/11465.contrib.rst new file mode 100644 index 00000000000..28e48909552 --- /dev/null +++ b/CHANGES/11465.contrib.rst @@ -0,0 +1 @@ +Fixed tests to run without trustme installed -- by :user:`kumaraditya303`. From 4d33e66428faf97c6a737f77aab729a45be38e68 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Thu, 4 Sep 2025 12:41:51 +0530 Subject: [PATCH 3/4] fix lint --- tests/conftest.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index 9d01e47c198..8e1dff1a07c 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -127,7 +127,9 @@ def client_ssl_ctx(tls_certificate_authority: "trustme.CA") -> ssl.SSLContext: @pytest.fixture -def tls_ca_certificate_pem_path(tls_certificate_authority: "trustme.CA") -> Iterator[str]: +def tls_ca_certificate_pem_path( + tls_certificate_authority: "trustme.CA", +) -> Iterator[str]: with tls_certificate_authority.cert_pem.tempfile() as ca_cert_pem: yield ca_cert_pem From ebfeac9cc855b294c4e409345ac53f8f774b4495 Mon Sep 17 00:00:00 2001 From: Kumar Aditya Date: Thu, 4 Sep 2025 15:04:50 +0530 Subject: [PATCH 4/4] fix test_client_functional --- tests/test_client_functional.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/test_client_functional.py b/tests/test_client_functional.py index e671aef180a..1d8a7bf582c 100644 --- a/tests/test_client_functional.py +++ b/tests/test_client_functional.py @@ -15,6 +15,7 @@ import zipfile from contextlib import suppress from typing import ( + TYPE_CHECKING, Any, AsyncIterator, Awaitable, @@ -29,7 +30,6 @@ from unittest import mock import pytest -import trustme from multidict import MultiDict from pytest_mock import MockerFixture from yarl import URL @@ -62,6 +62,9 @@ from aiohttp.test_utils import TestClient, TestServer, unused_port from aiohttp.typedefs import Handler, Query +if TYPE_CHECKING: + import trustme + @pytest.fixture(autouse=True) def cleanup( @@ -3259,7 +3262,7 @@ async def close(self) -> None: @pytest.fixture def create_server_for_url_and_handler( - aiohttp_server: AiohttpServer, tls_certificate_authority: trustme.CA + aiohttp_server: AiohttpServer, tls_certificate_authority: "trustme.CA" ) -> Callable[[URL, Handler], Awaitable[TestServer]]: def create(url: URL, srv: Handler) -> Awaitable[TestServer]: app = web.Application()