Skip to content

Commit 01dae57

Browse files
separate the mypy mock server from the others
1 parent 05a3db1 commit 01dae57

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ def factory() -> str:
724724
return factory
725725

726726

727-
@pytest.fixture(scope="session")
727+
@pytest.fixture
728728
def mock_server() -> Iterator[MockServer]:
729729
server = make_mock_server()
730730
test_server = MockServer(server)

tests/unit/test_network_lazy_wheel.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from pip._internal.network.session import PipSession
1313

1414
from tests.lib import TestData
15-
from tests.lib.server import MockServer, file_response
15+
from tests.lib.server import MockServer, file_response, make_mock_server
1616

1717
MYPY_0_782_WHL = (
1818
"https://files.pythonhosted.org/packages/9d/65/"
@@ -27,21 +27,32 @@
2727
}
2828

2929

30-
# NB: both the PipSession and any MockServer need use session scope in order to avoid
31-
# hangs on MacOS. The reason for this isn't clear.
3230
@pytest.fixture(scope="session")
3331
def session() -> PipSession:
3432
return PipSession()
3533

3634

35+
# Reusing the same session and mock server from conftest.py causes macOS CI runners to
36+
# error, so recreate it here. Similarly, using a function scope fixture causes macOS CI
37+
# runners to hang, so use session scope for all fixtures in this file.
3738
@pytest.fixture(scope="session")
38-
def mypy_whl_no_range(mock_server: MockServer, shared_data: TestData) -> Iterator[str]:
39+
def mypy_mock_server() -> Iterator[MockServer]:
40+
server = make_mock_server()
41+
test_server = MockServer(server)
42+
with test_server.context:
43+
yield test_server
44+
45+
46+
@pytest.fixture(scope="session")
47+
def mypy_whl_no_range(
48+
mypy_mock_server: MockServer, shared_data: TestData
49+
) -> Iterator[str]:
3950
mypy_whl = shared_data.packages / "mypy-0.782-py3-none-any.whl"
40-
mock_server.set_responses([file_response(mypy_whl)])
41-
mock_server.start()
42-
base_address = f"http://{mock_server.host}:{mock_server.port}"
51+
mypy_mock_server.set_responses([file_response(mypy_whl)])
52+
mypy_mock_server.start()
53+
base_address = f"http://{mypy_mock_server.host}:{mypy_mock_server.port}"
4354
yield "{}/{}".format(base_address, "mypy-0.782-py3-none-any.whl")
44-
mock_server.stop()
55+
mypy_mock_server.stop()
4556

4657

4758
@pytest.mark.network

0 commit comments

Comments
 (0)