mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-10-29 03:18:14 +08:00
29 lines
674 B
Python
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()
|