Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ephemeral ports in proxy tests #13234

Merged
merged 2 commits into from
Feb 23, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions tests/functional/test_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ def on_access_log(self, context: Dict[str, Any]) -> None:
def test_proxy_overrides_env(
script: PipTestEnvironment, capfd: pytest.CaptureFixture[str]
) -> None:
with proxy.Proxy(
port=8899,
num_acceptors=1,
), proxy.Proxy(plugins=[AccessLogPlugin], port=8888, num_acceptors=1):
script.environ["http_proxy"] = "127.0.0.1:8888"
script.environ["https_proxy"] = "127.0.0.1:8888"
with proxy.Proxy(port=0, num_acceptors=1) as proxy1, proxy.Proxy(
plugins=[AccessLogPlugin], port=0, num_acceptors=1
) as proxy2:
script.environ["http_proxy"] = f"127.0.0.1:{proxy2.flags.port}"
script.environ["https_proxy"] = f"127.0.0.1:{proxy2.flags.port}"
result = script.pip(
"download",
"--proxy",
"http://127.0.0.1:8899",
f"http://127.0.0.1:{proxy1.flags.port}",
"--trusted-host",
"127.0.0.1",
"-d",
Expand Down Expand Up @@ -72,12 +71,12 @@ def test_proxy_does_not_override_netrc(

netrc = script.scratch_path / ".netrc"
netrc.write_text(f"machine {server.host} login USERNAME password PASSWORD")
with proxy.Proxy(port=8888, num_acceptors=1), server_running(server):
with proxy.Proxy(port=0, num_acceptors=1) as proxy1, server_running(server):
script.environ["NETRC"] = netrc
script.pip(
"install",
"--proxy",
"http://127.0.0.1:8888",
f"http://127.0.0.1:{proxy1.flags.port}",
"--trusted-host",
"127.0.0.1",
"--no-cache-dir",
Expand All @@ -96,11 +95,14 @@ def test_proxy_does_not_override_netrc(
def test_build_deps_use_proxy_from_cli(
script: PipTestEnvironment, capfd: pytest.CaptureFixture[str], data: TestData
) -> None:
args = ["wheel", "-v", str(data.packages / "pep517_setup_and_pyproject")]
args.extend(["--proxy", "http://127.0.0.1:9000"])

with proxy.Proxy(port=9000, num_acceptors=1, plugins=[AccessLogPlugin]):
result = script.pip(*args)
with proxy.Proxy(port=0, num_acceptors=1, plugins=[AccessLogPlugin]) as proxy1:
result = script.pip(
"wheel",
"-v",
str(data.packages / "pep517_setup_and_pyproject"),
"--proxy",
f"http://127.0.0.1:{proxy1.flags.port}",
)

wheel_path = script.scratch / "pep517_setup_and_pyproject-1.0-py3-none-any.whl"
result.did_create(wheel_path)
Expand Down
Loading