Skip to content

Commit 4f2ccfc

Browse files
committed
Invalidate the user agent cache in tests
1 parent 91a69a5 commit 4f2ccfc

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

tests/unit/test_network_session.py

+9-2
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,17 @@
1010

1111
from pip import __version__
1212
from 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

1620
def 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

5966
def 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

6471
class TestPipSession:

0 commit comments

Comments
 (0)