MatthewFlamm / pytest-homeassistant-custom-component

Package to automatically extract testing plugins from Home Assistant for custom component testing
MIT License
68 stars 11 forks source link

A test tried to use socket.socket.connect() with host "localhost" (allowed: "127.0.0.1"). #178

Open alexschwantes opened 10 months ago

alexschwantes commented 10 months ago

Environment:

Operating System: win10 Development Environment: Visual Studio Code Python Version: 3.12.1 Pytest Version: 7.4.3 pytest-socket: 0.6.0 pytest-homeassistant-custom-component: 0.13.88

Steps to Reproduce:

Clone https://github.com/watkins-matt/home-assistant-google-keep-sync setup new venv and try to run pytest within vscode

Expected Behavior:

The test suite runs without any issues.

Actual Behavior:

The test suite fails to start, and the following error is displayed:

vscode_pytest.VSCodePytestError: Error attempting to connect to extension communication socket[vscode-pytest]: A test tried to use socket.socket.connect() with host "localhost" (allowed: "127.0.0.1").

Additional Information:

Tried the following without any luck:

Suggested Fix

The aparent source of the issue was found in a separate issue https://github.com/MatthewFlamm/pytest-homeassistant-custom-component/issues/171#issuecomment-1879449450

In plugin.py changing on line 144 change pytest_socket.socket_allow_hosts(["127.0.0.1"]) to pytest_socket.socket_allow_hosts(["127.0.0.1", "localhost"]) resolves the issue.

It would seem that this setting can't be overridden by these other settings listed above, only by allowing this plugin to accept hosts from localhost in addition to 127.0.0.1

Xyaren commented 7 months ago

Possibly solved by a new version of vscode: https://github.com/microsoft/vscode-python/issues/22383