Files
MoviePilot/tests/test_network_guard.py
DDSRem 2de976f6b3 Merge pull request #7050 from DDSRem-Dev/codex-comment-migration
docs: 统一全项目中文注释和结构化契约说明
2026-10-17 19:26:29 +08:00

29 lines
674 B
Python

"""
验证测试网络隔离边界与外部请求拦截。
"""
import socket
import pytest
from app.testing.network import block_real_network
def test_network_guard_fails_when_blocked_attempt_is_swallowed(monkeypatch):
"""
业务代码即使捕获网络异常,网络守卫仍应在用例收尾报告失败
"""
fixture = block_real_network.__wrapped__(monkeypatch)
next(fixture)
try:
try:
socket.getaddrinfo("external.example", 443)
except RuntimeError:
pass
with pytest.raises(pytest.fail.Exception, match="external.example"):
next(fixture)
finally:
monkeypatch.undo()