Skip to content

Commit 645d6f1

Browse files
committed
Limit addr to (host, port) even for IPv6
The address of an IPv6 socket as returned by getsockname() is a four-element tuple, rather than a two-element tuple as expected by the existing pytest_localserver.smtp module code. In this commit I'm extracting the first two elements of the tuple so that a Server's addr attribute will be a 2-tuple of (host, port) regardless of whether the underlying socket is an IPv4 or IPv6 socket.
1 parent 90d6c23 commit 645d6f1

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

pytest_localserver/smtp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def _set_server_socket_attributes(self):
8484
assert hasattr(self, 'port')
8585
return
8686

87-
self.addr = self.server.sockets[0].getsockname()
87+
self.addr = self.server.sockets[0].getsockname()[:2]
8888

8989
# Work around a bug/missing feature in aiosmtpd (https://github.com/aio-libs/aiosmtpd/issues/276)
9090
if self.port == 0:

0 commit comments

Comments
 (0)