错误内容:
E fixture 'host' not found
> available fixtures: cache, capfd, capfdbinary, caplog, capsys, capsysbinary, doctest_namespace, monkeypatch, pytestconfig, record_property, record_testsuite_property, record_xml_attribute, recwarn, tmp_path, tmp_path_factory, tmpdir, tmpdir_factory
> use 'pytest --fixtures [testpath]' for help on them.
错误代码
import socket
def test(host, port):
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.settimeout(4)
try:
t = (host,port)
client.connect(t)
print('%s:%d connect success !!' % (host, port))
except Exception:
print('%s:%d connect fail...' % (host, port))
test("192.168.0.1",80)
原因:
connect之后,没有关闭连接
import socket
def test(host, port):
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.settimeout(4)
try:
t = (host,port)
client.connect(t)
print('%s:%d connect success !!' % (host, port))
client.close() #●修正
except Exception:
print('%s:%d connect fail...' % (host, port))