proxy: add ca_cert property, get_proxy_url method · sysfce2/python-pytest-httpserver@5df2694 · GitHub
Skip to content

Commit 5df2694

Browse files
committed
proxy: add ca_cert property, get_proxy_url method
Plus extend pytest plugin a bit..
1 parent 45bb5c6 commit 5df2694

3 files changed

Lines changed: 28 additions & 10 deletions

File tree

pytest_httpserver/httpserver.py

Lines changed: 7 additions & 0 deletions

pytest_httpserver/pytest_plugin.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ def stop(self):
3131
Plugin.PROXY = None
3232

3333

34+
@pytest.fixture(scope="session")
35+
def plugin_httpserver_class():
36+
yield PluginHTTPServer
37+
38+
39+
@pytest.fixture(scope="session")
40+
def plugin_proxy_class():
41+
print("plugin_proxy_class")
42+
yield PluginHTTPProxy
43+
44+
3445
def get_httpserver_listen_address():
3546
listen_host = os.environ.get("PYTEST_HTTPSERVER_HOST")
3647
listen_port = os.environ.get("PYTEST_HTTPSERVER_PORT")
@@ -46,7 +57,7 @@ def httpserver_listen_address():
4657

4758

4859
@pytest.fixture
49-
def httpserver(httpserver_listen_address):
60+
def httpserver(httpserver_listen_address, plugin_httpserver_class):
5061
if Plugin.SERVER:
5162
Plugin.SERVER.clear()
5263
yield Plugin.SERVER
@@ -58,13 +69,13 @@ def httpserver(httpserver_listen_address):
5869
if not port:
5970
port = HTTPServer.DEFAULT_LISTEN_PORT
6071

61-
server = PluginHTTPServer(host=host, port=port)
72+
server = plugin_httpserver_class(host=host, port=port)
6273
server.start()
6374
yield server
6475

6576

6677
@pytest.fixture
67-
def httpproxy(httpserver_listen_address, tmp_path):
78+
def httpproxy(httpserver_listen_address, tmp_path, plugin_proxy_class):
6879
if Plugin.PROXY:
6980
Plugin.PROXY.clear()
7081
yield Plugin.PROXY
@@ -78,7 +89,7 @@ def httpproxy(httpserver_listen_address, tmp_path):
7889

7990
ca_dir = tmp_path.joinpath("httpproxy_ca")
8091
ca_dir.mkdir(exist_ok=True)
81-
server = PluginHTTPProxy(host=host, port=port, proxy_options={"ca_file_cache": str(ca_dir.joinpath("wsgiprox-ca.pem"))})
92+
server = plugin_proxy_class(host=host, port=port, proxy_options={"ca_file_cache": str(ca_dir.joinpath("wsgiprox-ca.pem"))})
8293
server.start()
8394
yield server
8495

tests/test_proxy.py

Lines changed: 6 additions & 6 deletions

0 commit comments

Comments
 (0)