File tree Expand file tree Collapse file tree 2 files changed +11
-2
lines changed
src/pip/_internal/network Expand file tree Collapse file tree 2 files changed +11
-2
lines changed Original file line number Diff line number Diff line change 33"""
44
55import email .utils
6+ import functools
67import io
78import ipaddress
89import json
@@ -106,6 +107,7 @@ def looks_like_ci() -> bool:
106107 return any (name in os .environ for name in CI_ENVIRONMENT_VARIABLES )
107108
108109
110+ @functools .lru_cache (maxsize = 1 )
109111def user_agent () -> str :
110112 """
111113 Return a string representing the user agent.
Original file line number Diff line number Diff line change 1010
1111from pip import __version__
1212from pip ._internal .models .link import Link
13- from pip ._internal .network .session import CI_ENVIRONMENT_VARIABLES , PipSession
13+ from pip ._internal .network .session import (
14+ CI_ENVIRONMENT_VARIABLES ,
15+ PipSession ,
16+ user_agent ,
17+ )
1418
1519
1620def get_user_agent () -> str :
21+ # These tests are testing the computation of the user agent, so we want to
22+ # avoid reusing cached values.
23+ user_agent .cache_clear ()
1724 return PipSession ().headers ["User-Agent" ]
1825
1926
@@ -58,7 +65,7 @@ def test_user_agent__ci(
5865
5966def test_user_agent_user_data (monkeypatch : pytest .MonkeyPatch ) -> None :
6067 monkeypatch .setenv ("PIP_USER_AGENT_USER_DATA" , "some_string" )
61- assert "some_string" in PipSession (). headers [ "User-Agent" ]
68+ assert "some_string" in get_user_agent ()
6269
6370
6471class TestPipSession :
You can’t perform that action at this time.
0 commit comments