From 8c64e0c65fa6a657ee5d5055ca89c43d8afdf99a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Date: Mon, 26 Jul 2021 16:08:58 +0200 Subject: [PATCH] Inline SERVER_SCOPE and remove typing_extensions requirement (#1773) --- tests/conftest.py | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index e2b98018..1ed87a46 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -14,7 +14,6 @@ from cryptography.hazmat.primitives.serialization import ( PrivateFormat, load_pem_private_key, ) -from typing_extensions import Literal from uvicorn.config import Config from uvicorn.main import Server @@ -165,38 +164,35 @@ async def redirect_301(scope, receive, send): await send({"type": "http.response.body"}) -SERVER_SCOPE: Literal["session"] = "session" - - -@pytest.fixture(scope=SERVER_SCOPE) +@pytest.fixture(scope="session") def cert_authority(): return trustme.CA() -@pytest.fixture(scope=SERVER_SCOPE) +@pytest.fixture(scope="session") def ca_cert_pem_file(cert_authority): with cert_authority.cert_pem.tempfile() as tmp: yield tmp -@pytest.fixture(scope=SERVER_SCOPE) +@pytest.fixture(scope="session") def localhost_cert(cert_authority): return cert_authority.issue_cert("localhost") -@pytest.fixture(scope=SERVER_SCOPE) +@pytest.fixture(scope="session") def cert_pem_file(localhost_cert): with localhost_cert.cert_chain_pems[0].tempfile() as tmp: yield tmp -@pytest.fixture(scope=SERVER_SCOPE) +@pytest.fixture(scope="session") def cert_private_key_file(localhost_cert): with localhost_cert.private_key_pem.tempfile() as tmp: yield tmp -@pytest.fixture(scope=SERVER_SCOPE) +@pytest.fixture(scope="session") def cert_encrypted_private_key_file(localhost_cert): # Deserialize the private key and then reserialize with a password private_key = load_pem_private_key( @@ -272,14 +268,14 @@ def serve_in_thread(server: Server): thread.join() -@pytest.fixture(scope=SERVER_SCOPE) +@pytest.fixture(scope="session") def server(): config = Config(app=app, lifespan="off", loop="asyncio") server = TestServer(config=config) yield from serve_in_thread(server) -@pytest.fixture(scope=SERVER_SCOPE) +@pytest.fixture(scope="session") def https_server(cert_pem_file, cert_private_key_file): config = Config( app=app,