Skip to content

Commit

Permalink
Merge pull request #1667 from jackwilsdon/fix-ipv6-test
Browse files Browse the repository at this point in the history
Fix test failing on systems without IPv6 support - thank you very much!
  • Loading branch information
pbiering authored Jan 2, 2025
2 parents ac8abbd + 532fad9 commit 45f2a4c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions radicale/tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,19 @@ def test_ssl(self) -> None:
def test_bind_fail(self) -> None:
for address_family, address in [(socket.AF_INET, "::1"),
(socket.AF_INET6, "127.0.0.1")]:
with socket.socket(address_family, socket.SOCK_STREAM) as sock:
if address_family == socket.AF_INET6:
# Only allow IPv6 connections to the IPv6 socket
sock.setsockopt(server.COMPAT_IPPROTO_IPV6,
socket.IPV6_V6ONLY, 1)
with pytest.raises(OSError) as exc_info:
sock.bind((address, 0))
try:
with socket.socket(address_family, socket.SOCK_STREAM) as sock:
if address_family == socket.AF_INET6:
# Only allow IPv6 connections to the IPv6 socket
sock.setsockopt(server.COMPAT_IPPROTO_IPV6,
socket.IPV6_V6ONLY, 1)
with pytest.raises(OSError) as exc_info:
sock.bind((address, 0))
except OSError as e:
if e.errno in (errno.EADDRNOTAVAIL, errno.EAFNOSUPPORT,
errno.EPROTONOSUPPORT):
continue
raise
# See ``radicale.server.serve``
assert (isinstance(exc_info.value, socket.gaierror) and
exc_info.value.errno in (
Expand Down

0 comments on commit 45f2a4c

Please sign in to comment.