Skip to content

Commit

Permalink
separate the mypy mock server from the others
Browse files Browse the repository at this point in the history
  • Loading branch information
cosmicexplorer committed Feb 23, 2025
1 parent 05a3db1 commit 56184b0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ def factory() -> str:
return factory


@pytest.fixture(scope="session")
@pytest.fixture
def mock_server() -> Iterator[MockServer]:
server = make_mock_server()
test_server = MockServer(server)
Expand Down
26 changes: 18 additions & 8 deletions tests/unit/test_network_lazy_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pip._internal.network.session import PipSession

from tests.lib import TestData
from tests.lib.server import MockServer, file_response
from tests.lib.server import MockServer, file_response, make_mock_server

MYPY_0_782_WHL = (
"https://files.pythonhosted.org/packages/9d/65/"
Expand All @@ -27,21 +27,31 @@
}


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


# Reusing the same session and mock server from conftest.py causes macOS CI runners to
# hang for some reason, so recreate it here.
@pytest.fixture(scope="session")
def mypy_whl_no_range(mock_server: MockServer, shared_data: TestData) -> Iterator[str]:
def mypy_mock_server() -> Iterator[MockServer]:
server = make_mock_server()
test_server = MockServer(server)
with test_server.context:
yield test_server


@pytest.fixture(scope="session")
def mypy_whl_no_range(
mypy_mock_server: MockServer, shared_data: TestData
) -> Iterator[str]:
mypy_whl = shared_data.packages / "mypy-0.782-py3-none-any.whl"
mock_server.set_responses([file_response(mypy_whl)])
mock_server.start()
base_address = f"http://{mock_server.host}:{mock_server.port}"
mypy_mock_server.set_responses([file_response(mypy_whl)])
mypy_mock_server.start()
base_address = f"http://{mypy_mock_server.host}:{mypy_mock_server.port}"
yield "{}/{}".format(base_address, "mypy-0.782-py3-none-any.whl")
mock_server.stop()
mypy_mock_server.stop()


@pytest.mark.network
Expand Down

0 comments on commit 56184b0

Please sign in to comment.