Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import socket
import pytest
import testinfra
local_command = testinfra.get_backend('local://').get_module('Command')
@pytest.fixture()
def TCPConnection():
def connect(address, port, timeout=5):
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(timeout)
s.connect((address, port))
s.close()
return 'established'
except socket.timeout:
return 'timed out'
except socket.error:
return 'refused'
return connect
@pytest.mark.parametrize("address,port", [
("goole.com", 443),
("goole.com", 80),
])
def test_connection(host, address, port):
assert host.TcpConnection(address, port) == "established"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment