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
+17
View File
@@ -0,0 +1,17 @@
"""The suite runs the same on any machine: no test reaches the network."""
import socket
import pytest
@pytest.mark.unit
@pytest.mark.parametrize("connect", [
lambda: socket.create_connection(("192.0.2.1", 80), timeout=1),
lambda: socket.socket().connect_ex(("192.0.2.1", 80)),
], ids=["connect", "connect_ex"])
def test_a_test_cannot_reach_the_network(connect):
"""A test that silently depends on a live vendor passes or fails with the
machine it runs on; conftest refuses the connection instead."""
with pytest.raises(OSError, match="reach the network"):
connect()