From: Seth Michael Larson Date: Mon, 2 Sep 2019 21:12:52 +0000 (-0500) Subject: Add os.environ fixture (#308) X-Git-Tag: 0.7.3~24 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b8c5e7a8528978e646c28a5837df5085ea3803fc;p=thirdparty%2Fhttpx.git Add os.environ fixture (#308) --- diff --git a/tests/conftest.py b/tests/conftest.py index 86a99342..bcef1595 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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):