@@ -25,16 +25,15 @@ def on_access_log(self, context: Dict[str, Any]) -> None:
25
25
def test_proxy_overrides_env (
26
26
script : PipTestEnvironment , capfd : pytest .CaptureFixture [str ]
27
27
) -> 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 } "
34
33
result = script .pip (
35
34
"download" ,
36
35
"--proxy" ,
37
- "http://127.0.0.1:8899 " ,
36
+ f "http://127.0.0.1:{ proxy1 . flags . port } " ,
38
37
"--trusted-host" ,
39
38
"127.0.0.1" ,
40
39
"-d" ,
@@ -72,12 +71,12 @@ def test_proxy_does_not_override_netrc(
72
71
73
72
netrc = script .scratch_path / ".netrc"
74
73
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 ):
76
75
script .environ ["NETRC" ] = netrc
77
76
script .pip (
78
77
"install" ,
79
78
"--proxy" ,
80
- "http://127.0.0.1:8888 " ,
79
+ f "http://127.0.0.1:{ proxy1 . flags . port } " ,
81
80
"--trusted-host" ,
82
81
"127.0.0.1" ,
83
82
"--no-cache-dir" ,
@@ -96,11 +95,14 @@ def test_proxy_does_not_override_netrc(
96
95
def test_build_deps_use_proxy_from_cli (
97
96
script : PipTestEnvironment , capfd : pytest .CaptureFixture [str ], data : TestData
98
97
) -> 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
+ )
104
106
105
107
wheel_path = script .scratch / "pep517_setup_and_pyproject-1.0-py3-none-any.whl"
106
108
result .did_create (wheel_path )
0 commit comments