Merge pull request #8499 from jdufresne/monkeypatch

Replace modify_env() with pytest monkeypatch.setenv()
This commit is contained in:
Takeshi KOMIYA
2020-11-28 09:22:44 +09:00
committed by GitHub
2 changed files with 4 additions and 19 deletions

View File

@@ -24,7 +24,7 @@ import requests
from sphinx.builders.linkcheck import CheckExternalLinksBuilder, RateLimit
from sphinx.util.console import strip_colors
from .utils import CERT_FILE, http_server, https_server, modify_env
from .utils import CERT_FILE, http_server, https_server
ts_re = re.compile(r".*\[(?P<ts>.*)\].*")
@@ -361,8 +361,9 @@ def test_connect_to_selfsigned_with_tls_cacerts(app):
@pytest.mark.sphinx('linkcheck', testroot='linkcheck-localserver-https', freshenv=True)
def test_connect_to_selfsigned_with_requests_env_var(app):
with modify_env(REQUESTS_CA_BUNDLE=CERT_FILE), https_server(OKHandler):
def test_connect_to_selfsigned_with_requests_env_var(monkeypatch, app):
monkeypatch.setenv("REQUESTS_CA_BUNDLE", CERT_FILE)
with https_server(OKHandler):
app.builder.build_all()
with open(app.outdir / 'output.json') as fp:

View File

@@ -1,6 +1,5 @@
import contextlib
import http.server
import os
import pathlib
import ssl
import threading
@@ -48,18 +47,3 @@ def create_server(thread_class):
http_server = create_server(HttpServerThread)
https_server = create_server(HttpsServerThread)
@contextlib.contextmanager
def modify_env(**env):
original_env = os.environ.copy()
for k, v in env.items():
os.environ[k] = v
try:
yield
finally:
for k in env:
try:
os.environ[k] = original_env[k]
except KeyError:
del os.environ[k]