Skip to content

Commit ae1b526

Browse files
authored
Merge pull request #13234 from sbidoul/proxy-tests-ephemeral-ports-sbi
Use ephemeral ports in proxy tests
2 parents e930fee + cbf2d30 commit ae1b526

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

tests/functional/test_proxy.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ def on_access_log(self, context: Dict[str, Any]) -> None:
2525
def test_proxy_overrides_env(
2626
script: PipTestEnvironment, capfd: pytest.CaptureFixture[str]
2727
) -> None:
28-
with proxy.Proxy(
29-
port=8899,
30-
num_acceptors=1,
31-
), proxy.Proxy(plugins=[AccessLogPlugin], port=8888, num_acceptors=1):
32-
script.environ["http_proxy"] = "127.0.0.1:8888"
33-
script.environ["https_proxy"] = "127.0.0.1:8888"
28+
with proxy.Proxy(port=0, num_acceptors=1) as proxy1, proxy.Proxy(
29+
plugins=[AccessLogPlugin], port=0, num_acceptors=1
30+
) as proxy2:
31+
script.environ["http_proxy"] = f"127.0.0.1:{proxy2.flags.port}"
32+
script.environ["https_proxy"] = f"127.0.0.1:{proxy2.flags.port}"
3433
result = script.pip(
3534
"download",
3635
"--proxy",
37-
"http://127.0.0.1:8899",
36+
f"http://127.0.0.1:{proxy1.flags.port}",
3837
"--trusted-host",
3938
"127.0.0.1",
4039
"-d",
@@ -72,12 +71,12 @@ def test_proxy_does_not_override_netrc(
7271

7372
netrc = script.scratch_path / ".netrc"
7473
netrc.write_text(f"machine {server.host} login USERNAME password PASSWORD")
75-
with proxy.Proxy(port=8888, num_acceptors=1), server_running(server):
74+
with proxy.Proxy(port=0, num_acceptors=1) as proxy1, server_running(server):
7675
script.environ["NETRC"] = netrc
7776
script.pip(
7877
"install",
7978
"--proxy",
80-
"http://127.0.0.1:8888",
79+
f"http://127.0.0.1:{proxy1.flags.port}",
8180
"--trusted-host",
8281
"127.0.0.1",
8382
"--no-cache-dir",
@@ -96,11 +95,14 @@ def test_proxy_does_not_override_netrc(
9695
def test_build_deps_use_proxy_from_cli(
9796
script: PipTestEnvironment, capfd: pytest.CaptureFixture[str], data: TestData
9897
) -> None:
99-
args = ["wheel", "-v", str(data.packages / "pep517_setup_and_pyproject")]
100-
args.extend(["--proxy", "http://127.0.0.1:9000"])
101-
102-
with proxy.Proxy(port=9000, num_acceptors=1, plugins=[AccessLogPlugin]):
103-
result = script.pip(*args)
98+
with proxy.Proxy(port=0, num_acceptors=1, plugins=[AccessLogPlugin]) as proxy1:
99+
result = script.pip(
100+
"wheel",
101+
"-v",
102+
str(data.packages / "pep517_setup_and_pyproject"),
103+
"--proxy",
104+
f"http://127.0.0.1:{proxy1.flags.port}",
105+
)
104106

105107
wheel_path = script.scratch / "pep517_setup_and_pyproject-1.0-py3-none-any.whl"
106108
result.did_create(wheel_path)

0 commit comments

Comments
 (0)