test: keep tests off the network

- conftest refuses socket connections outside tests marked integration
- the one test that probed Yahoo for real now stubs the reachability check
This commit is contained in:
Yijia-Xiao
2026-09-24 05:00:36 +00:00
parent 1e9ad314d8
commit 91c4319147
3 changed files with 35 additions and 0 deletions
+14
View File
@@ -1,6 +1,7 @@
"""Shared pytest fixtures that prevent CI hangs when API keys are absent."""
import os
import socket
import pytest
@@ -31,6 +32,19 @@ def pytest_configure(config):
config.addinivalue_line("markers", f"{marker}: {marker}-level tests")
@pytest.fixture(autouse=True)
def _no_network(request, monkeypatch):
"""Tests do not reach the network; one that must is marked integration."""
if request.node.get_closest_marker("integration"):
return
def refuse(self, address):
raise OSError(f"test tried to reach the network: {address}")
monkeypatch.setattr(socket.socket, "connect", refuse)
monkeypatch.setattr(socket.socket, "connect_ex", refuse)
_API_KEY_ENV_VARS = (
"OPENAI_API_KEY",
"GOOGLE_API_KEY",