]> git.ipfire.org Git - thirdparty/httpx.git/commitdiff
Add os.environ fixture (#308)
authorSeth Michael Larson <sethmichaellarson@gmail.com>
Mon, 2 Sep 2019 21:12:52 +0000 (16:12 -0500)
committerFlorimond Manca <florimond.manca@gmail.com>
Mon, 2 Sep 2019 21:12:52 +0000 (23:12 +0200)
tests/conftest.py

index 86a993426b00cbffb4f9f54f023f36a0830fd0d8..bcef1595264e254b194c7aa9374a49eacfe2b864 100644 (file)
@@ -1,6 +1,8 @@
 import asyncio
+import os
 import threading
 import time
+import typing
 
 import pytest
 import trustme
@@ -14,6 +16,28 @@ from uvicorn.main import Server
 
 from httpx import URL, AsyncioBackend
 
+ENVIRONMENT_VARIABLES = (
+    "SSL_CERT_FILE",
+    "REQUESTS_CA_BUNDLE",
+    "CURL_CA_BUNDLE",
+    "HTTP_PROXY",
+    "HTTPS_PROXY",
+    "ALL_PROXY",
+    "NO_PROXY",
+    "SSLKEYLOGFILE",
+)
+
+
+@pytest.fixture(scope="function", autouse=True)
+def clean_environ() -> typing.Dict[str, typing.Any]:
+    """Keeps os.environ clean for every test without having to mock os.environ"""
+    original_environ = os.environ.copy()
+    for key in ENVIRONMENT_VARIABLES:
+        os.environ.pop(key, None)
+    yield
+    os.environ.clear()
+    os.environ.update(original_environ)
+
 
 @pytest.fixture(params=[pytest.param(AsyncioBackend, marks=pytest.mark.asyncio)])
 def backend(request):