MCPcopy
hub / github.com/pyodide/pyodide / test_socket_connection_refused

Function test_socket_connection_refused

src/tests/test_python_socket.py:218–237  ·  view source on GitHub ↗

Test that connecting to a non-listening port raises an error.

(selenium_nodesock)

Source from the content-addressed store, hash-verified

216
217
218def test_socket_connection_refused(selenium_nodesock):
219 """Test that connecting to a non-listening port raises an error."""
220 # Bind to port 0, get the assigned port, then close immediately.
221 # This gives us a port that is almost certainly not listening.
222 tmp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
223 tmp.bind(("127.0.0.1", 0))
224 _, port = tmp.getsockname()
225 tmp.close()
226
227 @run_in_pyodide(packages=["pytest"])
228 def run(selenium, port):
229 import socket
230
231 import pytest
232
233 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
234 with pytest.raises(OSError):
235 s.connect(("127.0.0.1", port))
236
237 run(selenium_nodesock, port)
238
239
240def test_socket_recv_after_close(selenium_nodesock):

Callers

nothing calls this directly

Calls 3

bindMethod · 0.80
runFunction · 0.70
closeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…