@@ -348,11 +348,6 @@ The :mod:`test.support` module defines the following constants:
348348 :data: `SHORT_TIMEOUT `.
349349
350350
351- .. data :: IPV6_ENABLED
352-
353- Set to ``True `` if IPV6 is enabled on this host, ``False `` otherwise.
354-
355-
356351.
E880
. data :: SAVEDCWD
357352
358353 Set to :func: `os.getcwd `.
@@ -901,12 +896,6 @@ The :mod:`test.support` module defines the following functions:
901896 A decorator for running tests that require support for xattr.
902897
903898
904- .. decorator :: skip_unless_bind_unix_socket
905-
906- A decorator for running tests that require a functional bind() for Unix
907- sockets.
908-
909-
910899.. decorator :: anticipate_failure(condition)
911900
912901 A decorator to conditionally mark tests with
@@ -1157,31 +1146,6 @@ The :mod:`test.support` module defines the following functions:
11571146 is raised.
11581147
11591148
1160- .. function :: bind_port(sock, host=HOST)
1161-
1162- Bind the socket to a free port and return the port number. Relies on
1163- ephemeral ports in order to ensure we are using an unbound port. This is
1164- important as many tests may be running simultaneously, especially in a
1165- buildbot environment. This method raises an exception if the
1166- ``sock.family `` is :const: `~socket.AF_INET ` and ``sock.type `` is
1167- :const: `~socket.SOCK_STREAM `, and the socket has
1168- :const: `~socket.SO_REUSEADDR ` or :const: `~socket.SO_REUSEPORT ` set on it.
1169- Tests should never set these socket options for TCP/IP sockets.
1170- The only case for setting these options is testing multicasting via
1171- multiple UDP sockets.
1172-
1173- Additionally, if the :const: `~socket.SO_EXCLUSIVEADDRUSE ` socket option is
1174- available (i.e. on Windows), it will be set on the socket. This will
1175- prevent anyone else from binding to our host/port for the duration of the
1176- test.
1177-
1178-
1179- .. function :: bind_unix_socket(sock, addr)
1180-
1181- Bind a unix socket, raising :exc: `unittest.SkipTest ` if
1182- :exc: `PermissionError ` is raised.
1183-
1184-
11851149.. function :: catch_threading_exception()
11861150
11871151 Context manager catching :class: `threading.Thread ` exception using
@@ -1243,29 +1207,6 @@ The :mod:`test.support` module defines the following functions:
12431207 .. versionadded :: 3.8
12441208
12451209
1246- .. function :: find_unused_port(family=socket.AF_INET, socktype=socket.SOCK_STREAM)
1247-
1248- Returns an unused port that should be suitable for binding. This is
1249- achieved by creating a temporary socket with the same family and type as
1250- the ``sock `` parameter (default is :const: `~socket.AF_INET `,
1251- :const: `~socket.SOCK_STREAM `),
1252- and binding it to the specified host address (defaults to ``0.0.0.0 ``)
1253- with the port set to 0, eliciting an unused ephemeral port from the OS.
1254- The temporary socket is then closed and deleted, and the ephemeral port is
1255- returned.
1256-
1257- Either this method or :func: `bind_port ` should be used for any tests
1258- where a server socket needs to be bound to a particular port for the
1259- duration of the test.
1260- Which one to use depends on whether the calling code is creating a Python
1261- socket, or if an unused port needs to be provided in a constructor
1262- or passed to an external program (i.e. the ``-accept `` argument to
1263- openssl's s_server mode). Always prefer :func: `bind_port ` over
1264- :func: `find_unused_port ` where possible. Using a hard coded port is
1265- discouraged since it can make multiple instances of the test impossible to
1266- run simultaneously, which is a problem for buildbots.
1267-
1268-
12691210.. function :: load_package_tests(pkg_dir, loader, standard_tests, pattern)
12701211
12711212 Generic implementation of the :mod: `unittest ` ``load_tests `` protocol for
@@ -1481,6 +1422,77 @@ The :mod:`test.support` module defines the following classes:
14811422 it will be raised in :meth: `!__fspath__ `.
14821423
14831424
1425+ :mod: `test.support.socket_helper ` --- Utilities for socket tests
1426+ ================================================================
1427+
1428+ .. module :: test.support.socket_helper
1429+ :synopsis: Support for socket tests.
1430+
1431+
1432+ The :mod: `test.support.socket_helper ` module provides support for socket tests.
1433+
1434+ .. versionadded :: 3.9
1435+
1436+
1437+ .. data :: IPV6_ENABLED
1438+
1439+ Set to ``True `` if IPv6 is enabled on this host, ``False `` otherwise.
1440+
1441+
1442+ .. function :: find_unused_port(family=socket.AF_INET, socktype=socket.SOCK_STREAM)
1443+
1444+ Returns an unused port that should be suitable for binding. This is
1445+ achieved by creating a temporary socket with the same family and type as
1446+ the ``sock `` parameter (default is :const: `~socket.AF_INET `,
1447+ :const: `~socket.SOCK_STREAM `),
1448+ and binding it to the specified host address (defaults to ``0.0.0.0 ``)
1449+ with the port set to 0, eliciting an unused ephemeral port from the OS.
1450+ The temporary socket is then closed and deleted, and the ephemeral port is
1451+ returned.
1452+
1453+ Either this method or :func: `bind_port ` should be used for any tests
1454+ where a server socket needs to be bound to a particular port for the
1455+ duration of the test.
1456+ Which one to use depends on whether the calling code is creating a Python
1457+ socket, or if an unused port needs to be provided in a constructor
1458+ or passed to an external program (i.e. the ``-accept `` argument to
1459+ openssl's s_server mode). Always prefer :func: `bind_port ` over
1460+ :func: `find_unused_port ` where possible. Using a hard coded port is
1461+ discouraged since it can make multiple instances of the test impossible to
1462+ run simultaneously, which is a problem for buildbots.
1463+
1464+
1465+ .. function :: bind_port(sock, host=HOST)
1466+
1467+ Bind the socket to a free port and return the port number. Relies on
1468+ ephemeral ports in order to ensure we are using an unbound port. This is
1469+ important as many tests may be running simultaneously, especially in a
1470+ buildbot environment. This method raises an exception if the
1471+ ``sock.family `` is :const: `~socket.AF_INET ` and ``sock.type `` is
1472+ :const: `~socket.SOCK_STREAM `, and the socket has
1473+ :const: `~socket.SO_REUSEADDR ` or :const: `~socket.SO_REUSEPORT ` set on it.
1474+ Tests should never set these socket options for TCP/IP sockets.
1475+ The only case for setting these options is testing multicasting via
1476+ multiple UDP sockets.
1477+
1478+ Additionally, if the :const: `~socket.SO_EXCLUSIVEADDRUSE ` socket option is
1479+ available (i.e. on Windows), it will be set on the socket. This will
1480+ prevent anyone else from binding to our host/port for the duration of the
1481+ test.
1482+
1483+
1484+ .. function :: bind_unix_socket(sock, addr)
1485+
1486+ Bind a unix socket, raising :exc: `unittest.SkipTest ` if
1487+ :exc: `PermissionError ` is raised.
1488+
1489+
1490+ .. decorator :: skip_unless_bind_unix_socket
1491+
1492+ A decorator for running tests that require a functional ``bind() `` for Unix
1493+ sockets.
1494+
1495+
14841496:mod: `test.support.script_helper ` --- Utilities for the Python execution tests
14851497==============================================================================
14861498
0 commit comments